home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / RTrace-1.0-src / macdialogs.c < prev    next >
Text File  |  1992-10-27  |  171KB  |  4,238 lines

  1. /*****************************************************************************\
  2. * macdialogs.c                                                                *
  3. *                                                                             *
  4. * This file contains code which is specific to the Macintosh.  It implements  *
  5. * a macintosh interface for RTrace, which gets user input from a dialog box   *
  6. * and dumps it into rtrace as a command line.                                 *
  7. \*****************************************************************************/
  8.  
  9. #include "rtresources.h"
  10. #include "defs.h"
  11. #include "mactypes.h"
  12. #include "macdefaults.h"
  13. #include <ctype.h>
  14. #include <float.h>
  15. #include <limits.h>
  16. #include <string.h>
  17. #include <setjmp.h>
  18. #include <Movies.h>
  19.  
  20.  
  21. /* Globals */
  22. MenuHandle    antialiasing_menu;        /* Handles to the MENU resources of */
  23. MenuHandle    lighting_menu;            /* the popup menus in the options   */
  24. MenuHandle    normal_menu;            /* dialog.                          */
  25. MenuHandle    intersect_menu;
  26. MenuHandle    texture_menu;
  27. MenuHandle    shading_menu;
  28. MenuHandle    view_menu;
  29. MenuHandle    stereo_separation_menu;
  30. MenuHandle    sampling_level_menu;
  31. MenuHandle    save_file_type_menu;
  32. MenuHandle    save_anim_file_type_menu;
  33.  
  34. short        antialiasing_menu_selection = 1;    /* current selections in  */
  35. short        lighting_menu_selection = 1;        /* the popup menus in the */
  36. short        normal_menu_selection = 1;            /* options dialog.        */
  37. short        intersect_menu_selection = 1;
  38. short        texture_menu_selection = 1;
  39. short        shading_menu_selection = 2;
  40. short        view_menu_selection = 1;
  41. short        stereo_separation_menu_selection = 1;
  42. short        sampling_level_menu_selection = 1;
  43. short        save_file_type_menu_selection = 1;
  44. short        save_anim_file_type_menu_selection = 1;
  45.  
  46. Point        antialiasing_menu_upper_left;    /* Upper left corner of the   */
  47. Point        lighting_menu_upper_left;        /* popup menus in the options */
  48. Point        normal_menu_upper_left;            /* dialog (global coords).    */
  49. Point        intersect_menu_upper_left;
  50. Point        texture_menu_upper_left;
  51. Point        shading_menu_upper_left;
  52. Point        view_menu_upper_left;
  53. Point        stereo_separation_menu_upper_left;
  54. Point        sampling_level_menu_upper_left;
  55. Point        save_file_type_menu_upper_left;
  56. Point        save_anim_file_type_menu_upper_left;
  57.  
  58. ControlHandle    intersect_adjust_checkbox;        /* handles to the checkbox controls */
  59. ControlHandle    use_jittered_sample_checkbox;
  60. ControlHandle    correct_texture_normal_checkbox;
  61. ControlHandle    specify_focal_distance_checkbox;
  62. ControlHandle    allow_background_tasks_checkbox;
  63. ControlHandle    show_image_rendering_checkbox;
  64. ControlHandle    keep_image_in_memory_checkbox;
  65. ControlHandle    show_status_window_checkbox;
  66. ControlHandle    show_about_window_checkbox;
  67. ControlHandle    hide_options_window_checkbox;
  68. ControlHandle    animate_checkbox;
  69.  
  70. ControlHandle    render_button_handle;            /* handle to the Render button */
  71. ControlHandle    animation_okay_button_handle;    /* handle to the Okay button in animation */
  72. ControlHandle    preferences_okay_button_handle;    /* handle to the Okay button in preferences */
  73. ControlHandle    about_more_button_handle;        /* handle to the More button in About... */
  74.  
  75. DialogPtr        options_dialog;            /* the options dialog */
  76. DialogRecord    options_dialog_rec;        /* storage for the options dialog */
  77. DialogPtr        preferences_dialog;        /* the preferences dialog */
  78. DialogRecord    preferences_dialog_rec;    /* storage for the preferences dialog */
  79. DialogPtr        status_dialog;            /* the status dialog */
  80. DialogRecord    status_dialog_rec;        /* storage for the status dialog */
  81. DialogPtr        animation_dialog;        /* the animation dialog */
  82. DialogRecord    animation_dialog_rec;    /* storage for the animation dialog */
  83. DialogPtr        about_dialog;            /* the about dialog */
  84. DialogRecord    about_dialog_rec;        /* storage for the about dialog */
  85. DialogPtr        abort_render_dialog;    /* the Abort Render dialog */
  86. DialogRecord    abort_render_dialog_rec;/* storage for the Abort Render dialog */
  87. DialogPtr        cancel_dialog;            /* the Cancel dialog */
  88. DialogRecord    cancel_dialog_rec;        /* storage for the Cancel dialog */
  89. DialogPtr        error_dialog;            /* the Error dialog */
  90. DialogRecord    error_dialog_rec;        /* storage for the Error dialog */
  91. DialogPtr        prompt_save_dialog;        /* the Prompt to Save dialog */
  92. DialogRecord    prompt_save_dialog_rec;    /* storage for the Prompt to Save dialog */
  93. DialogPtr        param_error_dialog;        /* the Parameter Error dialog */
  94. DialogRecord    param_error_dialog_rec;    /* storage for the Parameter Error dialog */
  95. DialogPtr        invalid_num_dialog;        /* the Invalid Number Error dialog */
  96. DialogRecord    invalid_num_dialog_rec;    /* storage for the Invalid Number Error dialog */
  97. DialogPtr        offer_to_abort_dialog;    /* the Offer to Abort dialog */
  98. DialogRecord    offer_to_abort_dialog_rec;/* storage for the Offer to Abort dialog */
  99. DialogPtr        saving_frame_dialog;    /* the Saving Frame dialog */
  100. DialogRecord    saving_frame_dialog_rec;/* storage for the Saving Frame dialog */
  101.  
  102. long    image_width;    /* size of the image to be generated */
  103. long    image_height;
  104. long    time_between_events = 30;        /* number of ticks between calls to WaitNextEvent */
  105. long    last_texture_selection = -1;    /* the last setting of the textures mode */
  106. Boolean    allow_background_tasks = TRUE;    /* TRUE if we handle events and give time to
  107.                                             background processed while rendering */
  108. Boolean    show_image_rendering = TRUE;    /* TRUE if we show the image in a window */
  109. Boolean    keep_image_in_memory = TRUE;    /* TRUE if we keep a pixmap of the image in memory */
  110. Boolean    status_dialog_visible = FALSE;    /* TRUE if the status dialog is visible */
  111. Boolean    animation_dialog_visible = FALSE;/* TRUE if the animation dialog is visible */
  112. Boolean    image_window_visible = FALSE;    /* TRUE if the image window is visible */
  113. Boolean    show_status_window_flag = TRUE;    /* TRUE if the status dialog is shown each render */
  114. Boolean    show_about_window_flag = TRUE;    /* TRUE if the about window is shown at startup */
  115. Boolean    hide_options_window_flag = FALSE;/* TRUE if the options dialog is hidden each render */
  116.  
  117. long    progress_bar_max = 1;            /* maximum value of the progress bar */
  118. long    progress_bar_value = 0;            /* current_value of the progress bar */
  119. short    progress_bar_length;            /* length of the progress bar in the dialog */
  120. short    progress_bar_dividing_line;        /* length of the filled part of the progress bar */
  121.  
  122. long    sub_progress_bar_max = 1;        /* maximum value of the sub-progress bar */
  123. long    sub_progress_bar_value = 0;        /* current_value of the sub-progress bar */
  124. short    sub_progress_bar_length;        /* length of the sub-progress bar in the dialog */
  125. short    sub_progress_bar_dividing_line;    /* length of the filled part of the sub-progress bar */
  126.  
  127. PicHandle about_picture;                /* Handle to picture in about... dialog */
  128. PicHandle about_text_picture;            /* Handle to text picture in about... dialog */
  129. PicHandle about_credits_picture;        /* Handle to credits picture in about... dialog */
  130.  
  131. RGBColor bar_blue = {0xD000, 0xD000, 0xFFFF};    /* colors of the progress bars */
  132. RGBColor bar_gray = {0x4000, 0x4000, 0x4000};
  133. RGBColor bar_black = {0x0000, 0x0000, 0x0000};
  134.  
  135. Rect    about_rtrace_image_bounds;        /* Enclosing rectangle of the RTrace image in About... */
  136.  
  137. /* externals */
  138.  
  139. extern Boolean        image_complete;        /* TRUE if the image is completely rendered */
  140. extern char            sff_filename[200];    /* pathname of open .sff file */
  141. extern Boolean         is_offscreen_port;    /* TRUE when there is an offscreen CGrafPort */
  142. extern WindowPtr    image_window;        /* the image window data structures */
  143. extern Boolean        scene_in_memory;    /* TRUE if the scene for the current file is in memory */
  144. extern Boolean        rendering_same_file;/* TRUE if the file is same as last render */
  145. extern Boolean        texture_mode_changed;/* TRUE if the texture mode is different than last render */
  146. extern PicHandle    down_arrow_picture;    /* down arrows for popup */
  147. extern PicHandle    down_arrow_picture_grayed;
  148. extern MenuHandle    windows_menu;        /* the Windows pulldown menu */
  149. extern jmp_buf        environment;        /* Used to store environment to restore on error */
  150. extern MenuHandle    file_menu;
  151. extern Boolean        f8bit_QD_available;    /* TRUE if 8-bit QuickDraw is available */
  152. extern Boolean        f32bit_QD_available;/* TRUE if 32-bit QuickDraw is available */
  153. extern Boolean        quicktime_available;/* TRUE if QuickTime is available */
  154. extern Boolean         vbl_installed;        /* TRUE if the VBL event task is installed */
  155. extern Boolean        rendering;            /* TRUE while we are rendering */
  156. extern short        temp_folder_wd_id;    /* Working Directory refnum of Temporary Items */
  157.  
  158. extern short        display_depth;      /* Actual display depth in bits: 1, 4, 8, or 32 bits */
  159.  
  160.  
  161. /* definition of the callback routine which the Dialog Manager uses
  162.    when it calls a user item drawing routine */
  163.  
  164. typedef pascal void (*UserItemProc) (WindowPtr, short);
  165.  
  166.  
  167. /* Prototypes */
  168. void init_alert_dialogs(void);
  169. void setup_useritems(void);
  170. void show_options_dialog(Boolean bring_to_front);
  171. void hide_options_dialog(void);
  172. void handle_options_selection(short item_hit);
  173. void draw_popup (Rect *the_box, Str255 the_string, short enabled);
  174. void handle_antialiasing_popup_click(void);
  175. void setup_popup_menu (short useritem_id, UserItemProc *proc);
  176. void handle_popup_click(DialogPtr the_dialog, MenuHandle popup_menu, short menu_id,
  177.                         short popup_text_id, short popup_useritem_id,
  178.                         Point menu_upper_left, short *menu_selection);
  179. void invert_item (short item_number);
  180. void draw_any_popup (DialogPtr the_dialog, short item_number, MenuHandle menu,
  181.                             short menu_selection, Point *upper_left);
  182. pascal void draw_button_border (WindowPtr the_window, short item_number);
  183. pascal void draw_about_picture (WindowPtr the_window, short item_number);
  184. pascal void draw_about_text_picture (WindowPtr the_window, short item_number);
  185. pascal void draw_about_credits_picture (WindowPtr the_window, short item_number);
  186. pascal void draw_progress_bar (WindowPtr the_window, short item_number);
  187. pascal void draw_sub_progress_bar (WindowPtr the_window, short item_number);
  188. pascal void draw_log_text (WindowPtr the_window, short item_number);
  189. pascal void draw_antialiasing_popup (WindowPtr the_window, short item_number);
  190. pascal void draw_lighting_popup (WindowPtr the_window, short item_number);
  191. pascal void draw_normal_popup (WindowPtr the_window, short item_number);
  192. pascal void draw_intersect_popup (WindowPtr the_window, short item_number);
  193. pascal void draw_texture_popup (WindowPtr the_window, short item_number);
  194. pascal void draw_shading_popup (WindowPtr the_window, short item_number);
  195. pascal void draw_view_popup (WindowPtr the_window, short item_number);
  196. pascal void draw_stereo_separation_popup (WindowPtr the_window, short item_number);
  197. pascal void draw_sampling_level_popup (WindowPtr the_window, short item_number);
  198. void install_popup_menu_hook(MenuHandle popup_menu);
  199. static pascal void MenuProc( short message, MenuHandle menu, Rect *menuRect,
  200.                     Point hitPt, short *whichItem);
  201. void FlushCache(void);
  202. Boolean TrapAvailable( short theTrap);
  203. void load_popup_menus(void);
  204. pascal void dim_focal_distance (WindowPtr the_window, short item_number);            
  205. pascal void dim_stereo_separation (WindowPtr the_window, short item_number);
  206. pascal void dim_relinquish_control (WindowPtr the_window, short item_number);
  207. pascal void dim_aliasing_threshold (WindowPtr the_window, short item_number);    
  208. pascal void dim_keep_image_in_memory (WindowPtr the_window, short item_number);
  209. pascal void dim_show_image_rendering (WindowPtr the_window, short item_number);
  210. void setup_check_boxes(void);
  211. void generate_params(params_struct *params);
  212. void add_parameter(params_struct *params, char *param);
  213. void handle_checkbox_click(ControlHandle check_box);
  214. void show_about_dialog(void);
  215. void init_dialogs(void);
  216. void do_preferences_dialog(void);
  217. pascal Boolean save_image_filter (DialogPtr the_dialog, EventRecord *the_event,
  218.                                     int *the_item);
  219. char *get_save_filename (void);
  220. void post_render(Boolean natural);
  221. void update_render_button(void);
  222. void ray_trace_sff(void);
  223. void reset_defaults(void);
  224. void dispose_offscreen_port (void);
  225. void show_options_dialog(Boolean bring_to_front);
  226. void hide_options_dialog(void);
  227. void show_status_dialog(Boolean bring_to_front);
  228. void hide_status_dialog(void);
  229. void show_image_window(Boolean bring_to_front);
  230. void hide_image_window(void);
  231. Boolean process_mac_event(void);
  232. void update_status_free_memory (void);
  233. void set_status_num_objects(long num_objects);
  234. void set_status_image_data_size(long image_size);
  235. void set_dialog_num(DialogPtr dialog, short item, long number);
  236. void set_dialog_real(DialogPtr dialog, short item, real number);
  237. void set_dialog_text(DialogPtr dialog, short item, Str255 string);
  238. void set_dialog_pict(DialogPtr dialog, short item, short pic_id);
  239. void set_status_text(Str255 string);
  240. void set_progress_bar_value(long value);
  241. void set_progress_bar_max(long value);
  242. void set_sub_progress_bar_value(long value);
  243. void set_sub_progress_bar_max(long value);
  244. void update_sub_progress_bar (void);
  245. void update_progress_bar (void);
  246. void place_window (WindowPtr window, Rect *bounds);
  247. void write_preferences(void);
  248. void show_animation_dialog(Boolean bring_to_front);
  249. void hide_animation_dialog(void);
  250. void handle_animation_selection(short item_hit);
  251. void remove_get_event_vbl(void);
  252. void install_get_event_vbl(void);
  253. Boolean is_valid_real(char *string);
  254. Boolean is_valid_int(char *string);
  255. Boolean is_valid_param_real(DialogPtr dialog, short text_item_id, short label_item_id,
  256.                             real min, real max, Boolean include_min, Boolean include_max);
  257. Boolean is_valid_param_int(DialogPtr dialog, short text_item_id, short label_item_id,
  258.                             long min, long max);
  259. Boolean are_valid_params(void);
  260. void run_rtrace_movie(void);
  261. void handle_preferences_selection(short item_hit);
  262. void show_preferences_dialog(void);
  263.  
  264.  
  265.  
  266. /*****************************************************************************\
  267. * procedure init_alert_dialogs                                                *
  268. *                                                                             *
  269. * Purpose: This procedure initializes the alert-style dialogs by loading them *
  270. *          into memory and setting them up.                                   *
  271. *                                                                             *
  272. * Created by: Greg Ferrar                                                     *
  273. * Created on: August 23, 1992                                                 *
  274. * Modified:                                                                   *
  275. \*****************************************************************************/
  276.  
  277. void init_alert_dialogs(void)
  278. {
  279.  
  280.     short    item_type;        /* the item type of a DITL item */
  281.     Handle    item_handle;    /* a handle to a DITL item */
  282.     Rect    item_box;        /* the bounding box of a DITL item */
  283.  
  284.     error_dialog = GetNewDialog (ERROR_DIALOG, &error_dialog_rec, (WindowPtr)-1L);
  285.     offer_to_abort_dialog = GetNewDialog (OFFER_TO_ABORT_DIALOG, &offer_to_abort_dialog_rec, (WindowPtr)-1L);
  286.  
  287.     /* Center the windows on the screen */
  288.     place_window(error_dialog, (Rect *) NULL);
  289.     place_window(offer_to_abort_dialog, (Rect *) NULL);
  290.  
  291.     /* Set up the border around the default button in the Offer To Abort dialog */
  292.     GetDItem (offer_to_abort_dialog, OFFER_ABORT_FRAME_BUTTON_USERITEM, &item_type, &item_handle, &item_box);
  293.     SetDItem (offer_to_abort_dialog, OFFER_ABORT_FRAME_BUTTON_USERITEM, item_type, draw_button_border, &item_box);
  294.  
  295.     /* Set up the border around the default button in the Error dialog */
  296.     GetDItem (error_dialog, ERROR_FRAME_BUTTON_USERITEM, &item_type, &item_handle, &item_box);
  297.     SetDItem (error_dialog, ERROR_FRAME_BUTTON_USERITEM, item_type, draw_button_border, &item_box);
  298.  
  299. }    /* init_alert_dialogs() */
  300.  
  301.  
  302.  
  303. /*****************************************************************************\
  304. * procedure init_dialogs                                                      *
  305. *                                                                             *
  306. * Purpose: This procedure initializes the dialogs by loading them into memory *
  307. *          and setting them up.                                               *
  308. *                                                                             *
  309. * Created by: Greg Ferrar                                                     *
  310. * Created on: August 23, 1992                                                 *
  311. * Modified:                                                                   *
  312. \*****************************************************************************/
  313.  
  314. void init_dialogs(void)
  315. {
  316.  
  317.     short    about_pict_id;
  318.     short    about_text_pict_id;
  319.     short    about_credits_pict_id;
  320.  
  321.     /* Read in the dialog boxes.  They are invisible */
  322.     options_dialog = GetNewDialog (OPTIONS_DLG, &options_dialog_rec, (WindowPtr)-1L);
  323.     preferences_dialog = GetNewDialog (PREFERENCES_DLG, &preferences_dialog_rec, (WindowPtr)-1L);
  324.     status_dialog = GetNewDialog (STATUS_DIALOG, &status_dialog_rec, (WindowPtr)-1L);
  325.     about_dialog = GetNewDialog (ABOUT_DLG, &about_dialog_rec, (WindowPtr)-1L);
  326.     animation_dialog = GetNewDialog (ANIMATION_DIALOG, &animation_dialog_rec, (WindowPtr)-1L);
  327.     abort_render_dialog = GetNewDialog (ABORT_RENDER_DIALOG, &abort_render_dialog_rec,
  328.                                             (WindowPtr)-1L);
  329.     cancel_dialog = GetNewDialog (CANCEL_DIALOG, &cancel_dialog_rec, (WindowPtr)-1L);
  330.     saving_frame_dialog = GetNewDialog (SAVING_FRAME_DIALOG, &saving_frame_dialog_rec,
  331.                                             (WindowPtr)-1L);
  332.     param_error_dialog = GetNewDialog (PARAM_ERROR_DIALOG,
  333.                                             ¶m_error_dialog_rec, (WindowPtr)-1L);
  334.     prompt_save_dialog = GetNewDialog (PROMPT_SAVE_DIALOG,
  335.                                             &prompt_save_dialog_rec, (WindowPtr)-1L);
  336.     invalid_num_dialog = GetNewDialog (INVALID_NUM_DIALOG,
  337.                                             &invalid_num_dialog_rec, (WindowPtr)-1L);
  338.     
  339.     /* Center the dialogs which should be centered */
  340.     place_window(preferences_dialog, (Rect *) NULL);
  341.     place_window(abort_render_dialog, (Rect *) NULL);
  342.     place_window(cancel_dialog, (Rect *) NULL);
  343.     place_window(saving_frame_dialog, (Rect *) NULL);
  344.     place_window(about_dialog, (Rect *) NULL);
  345.     place_window(param_error_dialog, (Rect *) NULL);
  346.     place_window(prompt_save_dialog, (Rect *) NULL);
  347.     place_window(invalid_num_dialog, (Rect *) NULL);
  348.  
  349.     /* Set the picture in the About... dialog to be as colorful as the
  350.         monitor permits */
  351.     if (display_depth >= 4)
  352.         {
  353.         if (display_depth == 32)
  354.             {
  355.             about_pict_id = ABOUT_PICT_32;
  356.             about_text_pict_id = ABOUT_TEXT_PICT_32;
  357.             about_credits_pict_id = ABOUT_CREDITS_8;
  358.             }
  359.             
  360.         else
  361.             {
  362.             about_pict_id = ABOUT_PICT_8;
  363.             about_text_pict_id = ABOUT_TEXT_PICT_8;
  364.             about_credits_pict_id = ABOUT_CREDITS_8;
  365.             }
  366.         }
  367.     else
  368.         {
  369.         about_pict_id = ABOUT_PICT_1;
  370.         about_text_pict_id = ABOUT_TEXT_PICT_1;
  371.         about_credits_pict_id = ABOUT_CREDITS_1;
  372.         }
  373.     
  374.     /* Read the pictures into memory */
  375.     about_picture = GetPicture(about_pict_id);
  376.     about_text_picture = GetPicture(about_text_pict_id);
  377.     about_credits_picture = GetPicture(about_credits_pict_id);
  378.     
  379.     /* Hide the credits picture for starters */
  380.     HideDItem (about_dialog, ABOUT_CREDITS_PICT_USERITEM);
  381.     
  382.     /* Select the first EditText item in the options dialog box */
  383.     SelIText (options_dialog, IMAGE_WIDTH_NUM, 0, 32767);
  384.     
  385.     /* read in the popup menu resources for the options dialog box, and
  386.         install the menu hooks */
  387.     load_popup_menus();
  388.     
  389.     /* set up the check boxes in the options dialog box */
  390.     setup_check_boxes();
  391.     
  392.     /* set up the popup menus and the frame around the active button */
  393.     setup_useritems();
  394.  
  395. }    /* init_dialogs() */
  396.  
  397.  
  398.  
  399. /*****************************************************************************\
  400. * procedure show_options_dialog                                               *
  401. *                                                                             *
  402. * Purpose: This procedure displays the options dialog.                        *
  403. *                                                                             *
  404. *                                                                             *
  405. * Created by: Greg Ferrar                                                     *
  406. * Created on: August 21, 1992                                                 *
  407. * Modified:                                                                   *
  408. *   WHO          WHEN             WHAT                                        *
  409. \*****************************************************************************/
  410.  
  411. void show_options_dialog(Boolean bring_to_front)
  412. {
  413.  
  414.     /* Show the window */
  415.     ShowWindow (options_dialog);
  416.  
  417.     /* Bring it to the front if we're supposed to */
  418.     SelectWindow (options_dialog);
  419.     
  420.     /* Select the Windows menu */
  421.     EnableItem (windows_menu, 0);
  422.     
  423.     /* Set the text to "Hide Options Window" */
  424.     SetItem (windows_menu, SHOW_OPTIONS_ITEM, "\pHide Options Window");
  425.     
  426. }    /* show_options_dialog() */
  427.  
  428.  
  429.  
  430. /*****************************************************************************\
  431. * procedure hide_options_dialog                                               *
  432. *                                                                             *
  433. * Purpose: This procedure hides the options dialog.                           *
  434. *                                                                             *
  435. *                                                                             *
  436. * Created by: Greg Ferrar                                                     *
  437. * Created on: August 21, 1992                                                 *
  438. * Modified:                                                                   *
  439. *   WHO          WHEN             WHAT                                        *
  440. \*****************************************************************************/
  441.  
  442. void hide_options_dialog(void)
  443. {
  444.  
  445.     /* Hide the window */
  446.     HideWindow (options_dialog);
  447.     
  448.     /* Set the text of the Windows menu to "Show Options Window" */
  449.     SetItem (windows_menu, SHOW_OPTIONS_ITEM, "\pShow Options Window");
  450.     
  451. }    /* hide_options_dialog() */
  452.  
  453.  
  454.  
  455. /*****************************************************************************\
  456. * procedure show_status_dialog                                                *
  457. *                                                                             *
  458. * Purpose: This procedure displays the status dialog.                         *
  459. *                                                                             *
  460. *                                                                             *
  461. * Created by: Greg Ferrar                                                     *
  462. * Created on: September 3, 1992                                               *
  463. * Modified:                                                                   *
  464. *   WHO          WHEN             WHAT                                        *
  465. \*****************************************************************************/
  466.  
  467. void show_status_dialog(Boolean bring_to_front)
  468. {
  469.  
  470.     /* Show the window */
  471.     ShowWindow (status_dialog);
  472.  
  473.     /* Bring it to the front if we're supposed to */
  474.     SelectWindow (status_dialog);
  475.     
  476.     /* Set the text to "Hide Status Window" */
  477.     SetItem (windows_menu, SHOW_STATUS_ITEM, "\pHide Status Window");
  478.     
  479.     /* Remember that the status dialog is visible */
  480.     status_dialog_visible = TRUE;
  481.     
  482. }    /* show_status_dialog() */
  483.  
  484.  
  485.  
  486. /*****************************************************************************\
  487. * procedure hide_status_dialog                                                *
  488. *                                                                             *
  489. * Purpose: This procedure hides the status dialog.                            *
  490. *                                                                             *
  491. *                                                                             *
  492. * Created by: Greg Ferrar                                                     *
  493. * Created on: September 3, 1992                                               *
  494. * Modified:                                                                   *
  495. *   WHO          WHEN             WHAT                                        *
  496. \*****************************************************************************/
  497.  
  498. void hide_status_dialog(void)
  499. {
  500.  
  501.     /* Hide the window */
  502.     HideWindow (status_dialog);
  503.     
  504.     /* Set the text of the Windows menu to "Show Status Window" */
  505.     SetItem (windows_menu, SHOW_STATUS_ITEM, "\pShow Status Window");
  506.  
  507.     /* Remember that the status dialog isn't visible */
  508.     status_dialog_visible = FALSE;
  509.  
  510. }    /* hide_status_dialog() */
  511.  
  512.  
  513.  
  514. /*****************************************************************************\
  515. * procedure show_animation_dialog                                             *
  516. *                                                                             *
  517. * Purpose: This procedure displays the animation dialog.                      *
  518. *                                                                             *
  519. *                                                                             *
  520. * Created by: Greg Ferrar                                                     *
  521. * Created on: September 9, 1992                                               *
  522. * Modified:                                                                   *
  523. *   WHO          WHEN             WHAT                                        *
  524. \*****************************************************************************/
  525.  
  526. void show_animation_dialog(Boolean bring_to_front)
  527. {
  528.  
  529.     /* Show the window */
  530.     ShowWindow (animation_dialog);
  531.  
  532.     /* Bring it to the front if we're supposed to */
  533.     SelectWindow (animation_dialog);
  534.     
  535.     /* Set the text to "Hide Animation Window" */
  536.     SetItem (windows_menu, SHOW_ANIMATION_ITEM, "\pHide Animation Window");
  537.     
  538.     /* Remember that the animation dialog is visible */
  539.     animation_dialog_visible = TRUE;
  540.     
  541. }    /* show_animation_dialog() */
  542.  
  543.  
  544.  
  545. /*****************************************************************************\
  546. * procedure hide_animation_dialog                                             *
  547. *                                                                             *
  548. * Purpose: This procedure hides the animation dialog.                         *
  549. *                                                                             *
  550. *                                                                             *
  551. * Created by: Greg Ferrar                                                     *
  552. * Created on: September 9, 1992                                               *
  553. * Modified:                                                                   *
  554. *   WHO          WHEN             WHAT                                        *
  555. \*****************************************************************************/
  556.  
  557. void hide_animation_dialog(void)
  558. {
  559.  
  560.     /* Hide the window */
  561.     HideWindow (animation_dialog);
  562.     
  563.     /* Set the text of the Windows menu to "Show Animation Window" */
  564.     SetItem (windows_menu, SHOW_ANIMATION_ITEM, "\pShow Animation Window");
  565.  
  566.     /* Remember that the animation dialog isn't visible */
  567.     animation_dialog_visible = FALSE;
  568.  
  569. }    /* hide_animation_dialog() */
  570.  
  571.  
  572.  
  573. /*****************************************************************************\
  574. * procedure show_image_window                                                 *
  575. *                                                                             *
  576. * Purpose: This procedure displays the image window.                          *
  577. *                                                                             *
  578. *                                                                             *
  579. * Created by: Greg Ferrar                                                     *
  580. * Created on: September 11, 1992                                              *
  581. * Modified:                                                                   *
  582. *   WHO          WHEN             WHAT                                        *
  583. \*****************************************************************************/
  584.  
  585. void show_image_window(Boolean bring_to_front)
  586. {
  587.  
  588.     /* Show the window */
  589.     ShowWindow (image_window);
  590.  
  591.     /* Bring it to the front if we're supposed to */
  592.     SelectWindow (image_window);
  593.     
  594.     /* Set the text to "Hide Image Window" */
  595.     SetItem (windows_menu, SHOW_IMAGE_ITEM, "\pHide Image Window");
  596.     
  597.     /* Remember that the image window is visible */
  598.     image_window_visible = TRUE;
  599.     
  600. }    /* show_image_window() */
  601.  
  602.  
  603.  
  604. /*****************************************************************************\
  605. * procedure hide_image_window                                                 *
  606. *                                                                             *
  607. * Purpose: This procedure hides the image window.                             *
  608. *                                                                             *
  609. *                                                                             *
  610. * Created by: Greg Ferrar                                                     *
  611. * Created on: September 11, 1992                                              *
  612. * Modified:                                                                   *
  613. *   WHO          WHEN             WHAT                                        *
  614. \*****************************************************************************/
  615.  
  616. void hide_image_window(void)
  617. {
  618.  
  619.     /* Hide the window */
  620.     HideWindow (image_window);
  621.     
  622.     /* Set the text of the Windows menu to "Show Image Window" */
  623.     SetItem (windows_menu, SHOW_IMAGE_ITEM, "\pShow Image Window");
  624.  
  625.     /* Remember that the image window isn't visible */
  626.     image_window_visible = FALSE;
  627.  
  628. }    /* hide_image_window() */
  629.  
  630.  
  631.  
  632. /*****************************************************************************\
  633. * procedure handle_options_selection                                          *
  634. *                                                                             *
  635. * Purpose: This procedure handles a selection in the options dialog.          *
  636. *                                                                             *
  637. * Parameters: item_hit: the item which was selected.                          *
  638. *                                                                             *
  639. * Created by: Greg Ferrar                                                     *
  640. * Created on: August 21, 1992                                                 *
  641. * Modified:                                                                   *
  642. *   WHO          WHEN             WHAT                                        *
  643. *   Greg Ferrar  9/1/92           Made options dialog modeless                *
  644. \*****************************************************************************/
  645.  
  646. void handle_options_selection(short item_hit)
  647. {
  648.  
  649.     switch (item_hit)
  650.         {
  651.         
  652.         /* If it was one of the popup menus, pop it up and get a selection */
  653.         case ANTIALIASING_POPUP:
  654.             handle_popup_click (options_dialog, antialiasing_menu, ANTIALIASING_MENU,
  655.                                 ANTIALIASING_POPUP_TEXT, ANTIALIASING_POPUP,
  656.                                 antialiasing_menu_upper_left,
  657.                                 &antialiasing_menu_selection);
  658.             break;
  659.  
  660.         case LIGHTING_POPUP:
  661.             handle_popup_click (options_dialog, lighting_menu, LIGHTING_MENU,
  662.                                 LIGHTING_POPUP_TEXT, LIGHTING_POPUP,
  663.                                 lighting_menu_upper_left, &lighting_menu_selection);
  664.             break;
  665.  
  666.         case NORMAL_POPUP:
  667.             handle_popup_click (options_dialog, normal_menu, NORMAL_MENU,
  668.                                 NORMAL_POPUP_TEXT, NORMAL_POPUP,
  669.                                 normal_menu_upper_left, &normal_menu_selection);
  670.             break;
  671.  
  672.         case INTERSECT_POPUP:
  673.             handle_popup_click (options_dialog, intersect_menu, INTERSECT_MENU,
  674.                                 INTERSECT_POPUP_TEXT, INTERSECT_POPUP,
  675.                                 intersect_menu_upper_left, &intersect_menu_selection);
  676.             break;
  677.  
  678.         case TEXTURE_POPUP:
  679.             handle_popup_click (options_dialog, texture_menu, TEXTURE_MENU,
  680.                                 TEXTURE_POPUP_TEXT, TEXTURE_POPUP,
  681.                                 texture_menu_upper_left, &texture_menu_selection);
  682.             break;
  683.  
  684.         case VIEW_POPUP:
  685.             handle_popup_click (options_dialog, view_menu, VIEW_MENU,
  686.                                 VIEW_POPUP_TEXT, VIEW_POPUP,
  687.                                 view_menu_upper_left, &view_menu_selection);
  688.             break;
  689.  
  690.         case STEREO_SEPARATION_POPUP:
  691.             handle_popup_click (options_dialog, stereo_separation_menu,
  692.                                 STEREO_SEPARATION_MENU, 0, STEREO_SEPARATION_POPUP,
  693.                                 stereo_separation_menu_upper_left,
  694.                                 &stereo_separation_menu_selection);
  695.             break;
  696.  
  697.         case SHADING_POPUP:
  698.             handle_popup_click (options_dialog, shading_menu, SHADING_MENU,
  699.                                 SHADING_POPUP_TEXT, SHADING_POPUP,
  700.                                 shading_menu_upper_left, &shading_menu_selection);
  701.             break;
  702.  
  703.         case SAMPLING_LEVEL_POPUP:
  704.             handle_popup_click (options_dialog, sampling_level_menu,
  705.                                 SAMPLING_LEVEL_MENU,
  706.                                 SAMPLING_LEVEL_TEXT, SAMPLING_LEVEL_POPUP,
  707.                                 sampling_level_menu_upper_left,
  708.                                 &sampling_level_menu_selection);
  709.             break;
  710.  
  711.         /* If it was one of the checkboxes, toggle it */
  712.         
  713.         case INTERSECT_ADJUST_CHECKBOX:
  714.             handle_checkbox_click (intersect_adjust_checkbox);
  715.             break;
  716.         
  717.         case CORRECT_TEXTURE_NORMAL_CHECKBOX:
  718.             handle_checkbox_click (correct_texture_normal_checkbox);
  719.             break;
  720.         
  721.         case SPECIFY_FOCAL_DISTANCE_CHECKBOX:
  722.             handle_checkbox_click (specify_focal_distance_checkbox);
  723.             break;            
  724.         
  725.         case USE_JITTERED_SAMPLE_CHECKBOX:
  726.             handle_checkbox_click (use_jittered_sample_checkbox);
  727.             break;            
  728.         
  729.         case ANIMATE_CHECKBOX:
  730.             handle_checkbox_click (animate_checkbox);
  731.             break;            
  732.         
  733.         case RENDER_BUTTON:
  734.         
  735.             /* If the parameters are all valid, then render */
  736.             if (are_valid_params())
  737.  
  738.                 ray_trace_sff();
  739.  
  740.             else    /* there was an error */
  741.                 
  742.                 /* If we're faking a button click, dehilight it */
  743.                 HiliteControl(render_button_handle, 0);
  744.             
  745.             break;
  746.             
  747.         case DEFAULTS_BUTTON:
  748.             reset_defaults();
  749.             break;
  750.  
  751.         case ANIMATION_BUTTON:
  752.             show_animation_dialog(TRUE);
  753.             break;
  754.  
  755.         default:;    /* all other items take care of themselves */
  756.         }
  757.  
  758. }    /* handle_options_selection() */
  759.  
  760.  
  761.  
  762. /*****************************************************************************\
  763. * procedure handle_animation_selection                                        *
  764. *                                                                             *
  765. * Purpose: This procedure handles a selection in the animation dialog.        *
  766. *                                                                             *
  767. * Parameters: item_hit: the item which was selected.                          *
  768. *                                                                             *
  769. * Created by: Greg Ferrar                                                     *
  770. * Created on: September 9, 1992                                               *
  771. * Modified:                                                                   *
  772. *   WHO          WHEN             WHAT                                        *
  773. \*****************************************************************************/
  774.  
  775. void handle_animation_selection(short item_hit)
  776. {
  777.  
  778.     switch (item_hit)
  779.         {
  780.         
  781.         case OKAY_BUTTON:
  782.         
  783.             /* Check for invalid number of frames */
  784.             if (!(is_valid_param_int(animation_dialog, NUM_FRAMES_NUM, NUM_FRAMES_LABEL,
  785.                                         1, INT_MAX)))
  786.                 /* Don't quit just yet */
  787.                 item_hit = 0;
  788.  
  789.             else
  790.                 {
  791.                         
  792.                 /* Okay was clicked-- hide the dialog, turn on the
  793.                     animate checkbox, and change Save Image... to Save Animation... */
  794.                 hide_animation_dialog();
  795.                 SetCtlValue(animate_checkbox, TRUE);
  796.                 SetItem(file_menu, SAVE_ITEM, "\pSave Animation…");
  797.  
  798.                 }
  799.             /* If we're faking a button click, dehilight it */
  800.             HiliteControl(animation_okay_button_handle, 0);
  801.  
  802.             break;
  803.             
  804.         case CANCEL_BUTTON:
  805.             
  806.             /* Cancel was clicked-- hide the dialog, turn off the
  807.                 animate checkbox, and change Save Animation... to
  808.                 Save Image... */
  809.             hide_animation_dialog();
  810.             SetCtlValue(animate_checkbox, FALSE);            
  811.             SetItem(file_menu, SAVE_ITEM, "\pSave Image…");
  812.  
  813.             break;
  814.  
  815.         default:;    /* all other items take care of themselves */
  816.         }
  817.  
  818. }    /* handle_animation_selection() */
  819.  
  820.  
  821.  
  822. /*****************************************************************************\
  823. * procedure reset_defaults                                                    *
  824. *                                                                             *
  825. * Purpose: This procedure resets the options dialog to its default values.    *
  826. *                                                                             *
  827. * Created by: Greg Ferrar                                                     *
  828. * Created on: September 1, 199                                                *
  829. * Modified:                                                                   *
  830. *   reid judd   Oct 13'92     restore PtoCstr for default string values         *
  831. \*****************************************************************************/
  832.  
  833. void    reset_defaults(void)
  834. {
  835.  
  836.     short    type;         /* the item type of a DITL item */
  837.     Handle    handle;         /* the handle to a DITL item */
  838.     Rect    box;         /* the bounding box of a DITL item */
  839.     char    tmpstr[250]; /* temporary string to store default items in */
  840.  
  841.     /* This procedure is just a list of assignments, as each item in the
  842.         dialog is reset to its default value */
  843.  
  844.     /* Set image width to default */
  845.     GetDItem (options_dialog, IMAGE_WIDTH_NUM, &type, &handle, &box);
  846.     strcpy( tmpstr, IMAGE_WIDTH_DEFAULT );
  847.      SetIText(handle, CtoPstr( tmpstr ) );
  848.     PtoCstr( tmpstr );
  849.      
  850.     /* Set image height to default */
  851.     GetDItem (options_dialog, IMAGE_HEIGHT_NUM, &type, &handle, &box);
  852.     strcpy( tmpstr, IMAGE_HEIGHT_DEFAULT );
  853.      SetIText(handle, CtoPstr( tmpstr ) );
  854.     PtoCstr( tmpstr );
  855.          
  856.     /* Set aliasing threshold to default */
  857.     GetDItem (options_dialog, ALIASING_THRESHOLD_NUM, &type, &handle, &box);
  858.     strcpy( tmpstr, ALIASING_THRESHOLD_DEFAULT );
  859.      SetIText(handle, CtoPstr( tmpstr ) );
  860.     PtoCstr( tmpstr );
  861.          
  862.     /* Set shading threshold to default */
  863.     GetDItem (options_dialog, SHADING_THRESHOLD_NUM, &type, &handle, &box);
  864.     strcpy( tmpstr, SHADING_THRESHOLD_DEFAULT );
  865.      SetIText(handle, CtoPstr( tmpstr ) );
  866.     PtoCstr( tmpstr );
  867.          
  868.     /* Set ambient threshold to default */
  869.     GetDItem (options_dialog, AMBIENT_THRESHOLD_NUM, &type, &handle, &box);
  870.     strcpy( tmpstr, AMBIENT_THRESHOLD_DEFAULT );
  871.      SetIText(handle, CtoPstr( tmpstr ) );
  872.     PtoCstr( tmpstr );
  873.          
  874.     /* Set focal aperature to default */
  875.     GetDItem (options_dialog, FOCAL_APERATURE_NUM, &type, &handle, &box);
  876.     strcpy( tmpstr, FOCAL_APERATURE_DEFAULT );
  877.      SetIText(handle, CtoPstr( tmpstr ) );
  878.     PtoCstr( tmpstr );
  879.          
  880.     /* Set stereo separation to default */
  881.     GetDItem (options_dialog, STEREO_SEPARATION_NUM, &type, &handle, &box);
  882.     strcpy( tmpstr, STEREO_SEPARATION_DEFAULT );
  883.     SetIText(handle, CtoPstr( tmpstr ) );
  884.     PtoCstr( tmpstr );
  885.     
  886.     /* Set cluster size to default */
  887.     GetDItem (options_dialog, CLUSTER_SIZE_NUM, &type, &handle, &box);
  888.     strcpy( tmpstr, CLUSTER_SIZE_DEFAULT );
  889.      SetIText(handle, CtoPstr( tmpstr ) );
  890.     PtoCstr( tmpstr );
  891.          
  892.     /* Set ambient levels to default */
  893.     GetDItem (options_dialog, AMBIENT_LEVELS_NUM, &type, &handle, &box);
  894.     strcpy( tmpstr, AMBIENT_LEVEL_DEFAULT );
  895.      SetIText(handle, CtoPstr( tmpstr ) );
  896.     PtoCstr( tmpstr );
  897.          
  898.     /* Set ambient samples to default */
  899.     GetDItem (options_dialog, AMBIENT_SAMPLES_NUM, &type, &handle, &box);
  900.     strcpy( tmpstr, AMBIENT_SAMPLES_DEFAULT );
  901.      SetIText(handle, CtoPstr( tmpstr ) );
  902.     PtoCstr( tmpstr );
  903.          
  904.     /* Set shading levels to default */
  905.     GetDItem (options_dialog, SHADING_LEVELS_NUM, &type, &handle, &box);
  906.     strcpy( tmpstr, SHADING_LEVELS_DEFAULT );
  907.      SetIText(handle, CtoPstr( tmpstr ) );
  908.     PtoCstr( tmpstr );
  909.          
  910.     /* Set focal distance to default */
  911.     GetDItem (options_dialog, FOCAL_DISTANCE_NUM, &type, &handle, &box);
  912.     strcpy( tmpstr, FOCAL_DISTANCE_DEFAULT );
  913.      SetIText(handle, CtoPstr( tmpstr ) );
  914.     PtoCstr( tmpstr );
  915.          
  916.     /* Uncheck all menus */
  917.     CheckItem (antialiasing_menu, antialiasing_menu_selection, FALSE);
  918.     CheckItem (lighting_menu, lighting_menu_selection, FALSE);
  919.     CheckItem (normal_menu, normal_menu_selection, FALSE);
  920.     CheckItem (intersect_menu, intersect_menu_selection, FALSE);
  921.     CheckItem (texture_menu, texture_menu_selection, FALSE);
  922.     CheckItem (shading_menu, shading_menu_selection, FALSE);
  923.     CheckItem (view_menu, view_menu_selection, FALSE);
  924.     CheckItem (stereo_separation_menu, stereo_separation_menu_selection, FALSE);
  925.     CheckItem (sampling_level_menu, sampling_level_menu_selection, FALSE);
  926.     
  927.     /* Set the menus to their default settings */
  928.     antialiasing_menu_selection = ANTIALIASING_DEFAULT + 1;
  929.     lighting_menu_selection = LIGHTING_DEFAULT + 1;
  930.     normal_menu_selection = NORMAL_DEFAULT + 1;
  931.     intersect_menu_selection = INTERSECT_DEFAULT + 1;
  932.     texture_menu_selection = TEXTURE_DEFAULT + 1;
  933.     shading_menu_selection = SHADING_DEFAULT + 1;
  934.     view_menu_selection = VIEW_DEFAULT + 1;
  935.     stereo_separation_menu_selection = STEREO_SEPARATION_MENU_DEFAULT + 1;
  936.     sampling_level_menu_selection = SAMPLING_LEVEL_DEFAULT + 1;
  937.  
  938.     /* Check the new selections in all menus */
  939.     CheckItem (antialiasing_menu, antialiasing_menu_selection, TRUE);
  940.     CheckItem (lighting_menu, lighting_menu_selection, TRUE);
  941.     CheckItem (normal_menu, normal_menu_selection, TRUE);
  942.     CheckItem (intersect_menu, intersect_menu_selection, TRUE);
  943.     CheckItem (texture_menu, texture_menu_selection, TRUE);
  944.     CheckItem (shading_menu, shading_menu_selection, TRUE);
  945.     CheckItem (view_menu, view_menu_selection, TRUE);
  946.     CheckItem (stereo_separation_menu, stereo_separation_menu_selection, TRUE);
  947.     CheckItem (sampling_level_menu, sampling_level_menu_selection, TRUE);
  948.     
  949.     /* Set the checkboxed to their defaults */
  950.     SetCtlValue (correct_texture_normal_checkbox, CORRECT_TEXTURE_NORMAL_DEFAULT);
  951.     SetCtlValue (intersect_adjust_checkbox, INTERSECT_ADJUST_DEFAULT);
  952.     SetCtlValue (use_jittered_sample_checkbox, USE_JITTERED_SAMPLE_DEFAULT);
  953.     SetCtlValue (specify_focal_distance_checkbox, SPECIFY_FOCAL_DISTANCE_DEFAULT);
  954.     
  955.     /* Update the dialog */
  956.     UpdtDialog(options_dialog, options_dialog->visRgn);
  957.  
  958. }
  959.  
  960.  
  961.  
  962. /*****************************************************************************\
  963. * procedure generate_params                                                   *
  964. *                                                                             *
  965. * Purpose: This procedure generates a parameter list for RTrace by looking at *
  966. *          the options dialog.                                                *
  967. *                                                                             *
  968. * Parameters: params: the parameters list structure to create                 *
  969. *                                                                             *
  970. * Created by: Greg Ferrar                                                     *
  971. * Created on: August 22, 1992                                                 *
  972. * Modified:                                                                   *
  973. \*****************************************************************************/
  974.  
  975. void    generate_params(params_struct *params)
  976. {
  977.  
  978.     short    type;        /* the item type of a DITL item */
  979.     Handle    handle;        /* the handle to a DITL item */
  980.     Rect    box;        /* the bounding box of a DITL item */
  981.     char    current_setting_str[200];    /* current setting of an option */
  982.     long    current_setting_num;        /* current setting of a menu option */
  983.     char    this_param[200];            /* parameter we're generating */
  984.  
  985.     /* This ugly procedure is a long list of comparisons which follow the
  986.         following general format:
  987.         
  988.             get_current_setting
  989.             if {current_setting != default setting}
  990.                 add_option_to_command_line                                */
  991.  
  992.     /* start with a "RTrace" */
  993.     add_parameter (params, "RTrace");
  994.     
  995.     /* do Image Width */
  996.     GetDItem (options_dialog, IMAGE_WIDTH_NUM, &type, &handle, &box);
  997.     GetIText (handle, current_setting_str);
  998.     StringToNum (current_setting_str, &image_width);
  999.     if (strcmp (PtoCstr(current_setting_str), IMAGE_WIDTH_DEFAULT))
  1000.         {
  1001.         strcpy (this_param, "w");
  1002.         strcat (this_param, current_setting_str);
  1003.         add_parameter (params, this_param);
  1004.         }
  1005.  
  1006.     /* do Image Height */
  1007.     GetDItem (options_dialog, IMAGE_HEIGHT_NUM, &type, &handle, &box);
  1008.     GetIText (handle, current_setting_str);
  1009.     StringToNum (current_setting_str, &image_height);
  1010.     if (strcmp (PtoCstr(current_setting_str), IMAGE_HEIGHT_DEFAULT))
  1011.         {
  1012.         strcpy (this_param, "h");
  1013.         strcat (this_param, current_setting_str);
  1014.         add_parameter (params, this_param);
  1015.         }
  1016.  
  1017.     /* do Aliasing Threshold */
  1018.     if (sampling_level_menu_selection != 1)
  1019.         {
  1020.         GetDItem (options_dialog, ALIASING_THRESHOLD_NUM, &type, &handle, &box);
  1021.         GetIText (handle, current_setting_str);
  1022.         if (strcmp (PtoCstr(current_setting_str), ALIASING_THRESHOLD_DEFAULT))
  1023.             {
  1024.             strcpy (this_param, "A");
  1025.             strcat (this_param, current_setting_str);
  1026.             add_parameter (params, this_param);
  1027.             }
  1028.         }
  1029.  
  1030.     /* do Shading Threshold */
  1031.     GetDItem (options_dialog, SHADING_THRESHOLD_NUM, &type, &handle, &box);
  1032.     GetIText (handle, current_setting_str);
  1033.     if (strcmp (PtoCstr(current_setting_str), SHADING_THRESHOLD_DEFAULT))
  1034.         {
  1035.         strcpy (this_param, "S");
  1036.         strcat (this_param, current_setting_str);
  1037.         add_parameter (params, this_param);
  1038.         }
  1039.  
  1040.     /* do Ambient Threshold */
  1041.     GetDItem (options_dialog, AMBIENT_THRESHOLD_NUM, &type, &handle, &box);
  1042.     GetIText (handle, current_setting_str);
  1043.     if (strcmp (PtoCstr(current_setting_str), AMBIENT_THRESHOLD_DEFAULT))
  1044.         {
  1045.         strcpy (this_param, "T");
  1046.         strcat (this_param, current_setting_str);
  1047.         add_parameter (params, this_param);
  1048.         }
  1049.  
  1050.     /* do Focal Aperature */
  1051.     GetDItem (options_dialog, FOCAL_APERATURE_NUM, &type, &handle, &box);
  1052.     GetIText (handle, current_setting_str);
  1053.     if (strcmp (PtoCstr(current_setting_str), FOCAL_APERATURE_DEFAULT))
  1054.         {
  1055.         strcpy (this_param, "P");
  1056.         strcat (this_param, current_setting_str);
  1057.         add_parameter (params, this_param);
  1058.         }
  1059.  
  1060.     /* do Stereo Separation */
  1061.     if (view_menu_selection != 1)
  1062.         {
  1063.         GetDItem (options_dialog, STEREO_SEPARATION_NUM, &type, &handle, &box);
  1064.         GetIText (handle, current_setting_str);
  1065.         if (strcmp (PtoCstr(current_setting_str), STEREO_SEPARATION_DEFAULT))
  1066.             {
  1067.             strcpy (this_param, "E");
  1068.             if (stereo_separation_menu_selection == 2)
  1069.                 strcat (this_param, "-");
  1070.             strcat (this_param, current_setting_str);
  1071.             add_parameter (params, this_param);
  1072.             }
  1073.         }
  1074.  
  1075.     /* do Cluster Size */
  1076.     GetDItem (options_dialog, CLUSTER_SIZE_NUM, &type, &handle, &box);
  1077.     GetIText (handle, current_setting_str);
  1078.     if (strcmp (PtoCstr(current_setting_str), CLUSTER_SIZE_DEFAULT))
  1079.         {
  1080.         strcpy (this_param, "c");
  1081.         strcat (this_param, current_setting_str);
  1082.         add_parameter (params, this_param);
  1083.         }
  1084.  
  1085.     /* do Ambient Level */
  1086.     GetDItem (options_dialog, AMBIENT_LEVELS_NUM, &type, &handle, &box);
  1087.     GetIText (handle, current_setting_str);
  1088.     if (strcmp (PtoCstr(current_setting_str), AMBIENT_LEVEL_DEFAULT))
  1089.         {
  1090.         strcpy (this_param, "d");
  1091.         strcat (this_param, current_setting_str);
  1092.         add_parameter (params, this_param);
  1093.         }
  1094.  
  1095.     /* do Ambient Samples */
  1096.     GetDItem (options_dialog, AMBIENT_SAMPLES_NUM, &type, &handle, &box);
  1097.     GetIText (handle, current_setting_str);
  1098.     if (strcmp (PtoCstr(current_setting_str), AMBIENT_SAMPLES_DEFAULT))
  1099.         {
  1100.         strcpy (this_param, "D");
  1101.         strcat (this_param, current_setting_str);
  1102.         add_parameter (params, this_param);
  1103.         }
  1104.  
  1105.     /* do Shading Levels */
  1106.     GetDItem (options_dialog, SHADING_LEVELS_NUM, &type, &handle, &box);
  1107.     GetIText (handle, current_setting_str);
  1108.     if (strcmp (PtoCstr(current_setting_str), SHADING_LEVELS_DEFAULT))
  1109.         {
  1110.         strcpy (this_param, "s");
  1111.         strcat (this_param, current_setting_str);
  1112.         add_parameter (params, this_param);
  1113.         }
  1114.  
  1115.     /* do Focal Distance */
  1116.     if (GetCtlValue (specify_focal_distance_checkbox))
  1117.         {
  1118.         GetDItem (options_dialog, FOCAL_DISTANCE_NUM, &type, &handle, &box);
  1119.         GetIText (handle, current_setting_str);
  1120.         if (strcmp (PtoCstr(current_setting_str), FOCAL_DISTANCE_DEFAULT))
  1121.             {
  1122.             strcpy (this_param, "F");
  1123.             strcat (this_param, current_setting_str);
  1124.             add_parameter (params, this_param);
  1125.             }
  1126.         }
  1127.  
  1128.     /* do Sampling Levels */
  1129.     current_setting_num = sampling_level_menu_selection - 1;
  1130.     if (current_setting_num != SAMPLING_LEVEL_DEFAULT)
  1131.         {
  1132.         strcpy (this_param, "p");
  1133.         NumToString (current_setting_num, current_setting_str);
  1134.         strcat (this_param, PtoCstr(current_setting_str));
  1135.         add_parameter (params, this_param);
  1136.         }
  1137.  
  1138.     /* do Antialiasing mode */
  1139.     current_setting_num = antialiasing_menu_selection - 1;
  1140.     if (current_setting_num != ANTIALIASING_DEFAULT)
  1141.         {
  1142.         strcpy (this_param, "a");
  1143.         NumToString (current_setting_num, current_setting_str);
  1144.         strcat (this_param, PtoCstr(current_setting_str));
  1145.         add_parameter (params, this_param);
  1146.         }
  1147.  
  1148.     /* do Lighting Mode */
  1149.     current_setting_num = lighting_menu_selection - 1;
  1150.     if (current_setting_num != LIGHTING_DEFAULT)
  1151.         {
  1152.         strcpy (this_param, "l");
  1153.         NumToString (current_setting_num, current_setting_str);
  1154.         strcat (this_param, PtoCstr(current_setting_str));
  1155.         add_parameter (params, this_param);
  1156.         }
  1157.  
  1158.     /* do Normal Mode */
  1159.     current_setting_num = normal_menu_selection - 1;
  1160.     if (current_setting_num != NORMAL_DEFAULT)
  1161.         {
  1162.         strcpy (this_param, "n");
  1163.         NumToString (current_setting_num, current_setting_str);
  1164.         strcat (this_param, PtoCstr(current_setting_str));
  1165.         add_parameter (params, this_param);
  1166.         }
  1167.  
  1168.     /* do Texture Mode (also remember the current setting for later) */
  1169.     last_texture_selection = texture_menu_selection - 1;
  1170.     if (last_texture_selection != TEXTURE_DEFAULT)
  1171.         {
  1172.         strcpy (this_param, "t");
  1173.         NumToString (last_texture_selection, current_setting_str);
  1174.         strcat (this_param, PtoCstr(current_setting_str));
  1175.         add_parameter (params, this_param);
  1176.         }
  1177.  
  1178.     /* do View Mode */
  1179.     current_setting_num = view_menu_selection - 1;
  1180.     if (current_setting_num != VIEW_DEFAULT)
  1181.         {
  1182.         strcpy (this_param, "v");
  1183.         NumToString (current_setting_num, current_setting_str);
  1184.         strcat (this_param, PtoCstr(current_setting_str));
  1185.         add_parameter (params, this_param);
  1186.         }
  1187.  
  1188.     /* do Intersect Mode */
  1189.     current_setting_num = intersect_menu_selection - 1;
  1190.     if (current_setting_num != INTERSECT_DEFAULT)
  1191.         {
  1192.         strcpy (this_param, "i");
  1193.         NumToString (current_setting_num, current_setting_str);
  1194.         strcat (this_param, PtoCstr(current_setting_str));
  1195.         add_parameter (params, this_param);
  1196.         }
  1197.  
  1198.     /* do Shading Mode */
  1199.     current_setting_num = shading_menu_selection - 1;
  1200.     if (current_setting_num != SHADING_DEFAULT)
  1201.         {
  1202.         strcpy (this_param, "m");
  1203.         NumToString (current_setting_num, current_setting_str);
  1204.         strcat (this_param, PtoCstr(current_setting_str));
  1205.         add_parameter (params, this_param);
  1206.         }
  1207.  
  1208.     /* do Correct Textures Normal */
  1209.     if (GetCtlValue (correct_texture_normal_checkbox))
  1210.         add_parameter (params, "z1");
  1211.  
  1212.     /* do Intersect Adjust */
  1213.     if (GetCtlValue (intersect_adjust_checkbox))
  1214.         add_parameter (params, "I1");
  1215.  
  1216.     /* do Jittered Sample */
  1217.     if (GetCtlValue (use_jittered_sample_checkbox))
  1218.         add_parameter (params, "j1");
  1219.  
  1220. }    /* generate_params() */
  1221.  
  1222.  
  1223.  
  1224. /*****************************************************************************\
  1225. * procedure add_parameter                                                     *
  1226. *                                                                             *
  1227. * Purpose: This procedure adds the passed parameter to the command line       *
  1228. *          parameters array.                                                  *
  1229. *                                                                             *
  1230. * Parameters: params: the existing parameters structure.                      *
  1231. *             param:  parameter to add                                        *
  1232. *                                                                             *
  1233. * Created by: Greg Ferrar                                                     *
  1234. * Created on: August 21, 1992                                                 *
  1235. * Modified:                                                                   *
  1236. \*****************************************************************************/
  1237.  
  1238. void    add_parameter(params_struct *params, char *param)
  1239. {
  1240.  
  1241.     /* copy this parameter into the parameter storage block */
  1242.     strcpy (params->storage + params->current_loc, param);
  1243.     
  1244.     /* Put a pointer to this parameter in the parameters array */
  1245.     params->parameters[params->current_param++] = params->storage + params->current_loc;
  1246.     
  1247.     /* mark the storage as used */
  1248.     params->current_loc += strlen (param) + 1;    
  1249.  
  1250. }    /* add_parameter() */
  1251.  
  1252.  
  1253.  
  1254. /*****************************************************************************\
  1255. * procedure are_valid_params                                                  *
  1256. *                                                                             *
  1257. * Purpose: This procedure verifies that all the editable text parameters in   *
  1258. *          the options dialog are valid.  It returns TRUE if they are.        *
  1259. *                                                                             *
  1260. * Parameters: returns TRUE parameters are valid.                              *
  1261. *                                                                             *
  1262. * Created by: Greg Ferrar                                                     *
  1263. * Created on: September 20, 1992                                              *
  1264. * Modified:                                                                   *
  1265. *   Reid Judd    Oct 16, '92    Allow Thresholds (Aliasing, Shading, and      *
  1266. *                                 ambient to range from 0.00001 to 0.99999    *
  1267. \*****************************************************************************/
  1268.  
  1269. Boolean are_valid_params(void)
  1270. {
  1271.  
  1272.     /* Check the Image Width */
  1273.     if (!is_valid_param_int(options_dialog, IMAGE_WIDTH_NUM, IMAGE_WIDTH_LABEL, 1, INT_MAX))
  1274.         return FALSE;
  1275.  
  1276.     /* Check the Image Height */
  1277.     if (!is_valid_param_int(options_dialog, IMAGE_HEIGHT_NUM, IMAGE_HEIGHT_LABEL, 1, INT_MAX))
  1278.         return FALSE;
  1279.         
  1280.     /* Check the Focal Aperature */
  1281.     if (!is_valid_param_real(options_dialog, FOCAL_APERATURE_NUM, FOCAL_APERATURE_LABEL,
  1282.                                 0, DBL_MAX, TRUE, TRUE))
  1283.         return FALSE;
  1284.  
  1285.     /* Check the Cluster Size */
  1286.     if (!is_valid_param_int(options_dialog, CLUSTER_SIZE_NUM, CLUSTER_SIZE_LABEL, 1, INT_MAX))
  1287.         return FALSE;
  1288.         
  1289.     /* Check the Shading Levels */
  1290.     if (!is_valid_param_int(options_dialog, SHADING_LEVELS_NUM, SHADING_LEVELS_LABEL, 1, INT_MAX))
  1291.         return FALSE;
  1292.         
  1293.     /* Check the Shading Threshold */
  1294.     if (!is_valid_param_real(options_dialog, SHADING_THRESHOLD_NUM, SHADING_THRESHOLD_LABEL,
  1295.                                 0.0000001, 1.0, TRUE, TRUE))
  1296.         return FALSE;
  1297.  
  1298.     /* Check the Ambient Samples */
  1299.     if (!is_valid_param_int(options_dialog, AMBIENT_SAMPLES_NUM, AMBIENT_SAMPLES_LABEL, 1, INT_MAX))
  1300.         return FALSE;
  1301.     
  1302.     /* Check the Ambient Levels */
  1303.     if (!is_valid_param_int(options_dialog, AMBIENT_LEVELS_NUM, AMBIENT_LEVELS_LABEL, 0, INT_MAX))
  1304.         return FALSE;
  1305.     
  1306.     /* Check the Ambient Threshold */
  1307.     if (!is_valid_param_real(options_dialog, AMBIENT_THRESHOLD_NUM, AMBIENT_THRESHOLD_LABEL,
  1308.                                 0.0, 1.0, TRUE, TRUE))
  1309.             return FALSE;
  1310.  
  1311.     /* Check the Aliasing Threshold, if any */
  1312.     if ((sampling_level_menu_selection != 1)
  1313.         && (!is_valid_param_real(options_dialog, ALIASING_THRESHOLD_NUM, ALIASING_THRESHOLD_LABEL,
  1314.                                 0.0, 1.0, TRUE, TRUE)))
  1315.         return FALSE;
  1316.  
  1317.     /* Check the Stereo Separation, if any */
  1318.     if ((view_menu_selection != 1)
  1319.         && (!is_valid_param_real(options_dialog, STEREO_SEPARATION_NUM,
  1320.                                     STEREO_SEPARATION_LABEL, 0, DBL_MAX, TRUE, TRUE)))
  1321.         return FALSE;
  1322.  
  1323.     /* Check the Focal Distance, if any */
  1324.     if ((GetCtlValue(specify_focal_distance_checkbox))
  1325.         && (!is_valid_param_real(options_dialog, FOCAL_DISTANCE_NUM,
  1326.                                     FOCAL_DISTANCE_LABEL, 0, DBL_MAX, TRUE, TRUE)))
  1327.         return FALSE;
  1328.     
  1329.     /* Everything is okay */
  1330.     return TRUE;
  1331.     
  1332. }    /* are_valid_params() */
  1333.  
  1334.  
  1335.  
  1336. /*****************************************************************************\
  1337. * procedure is_valid_param_int                                                *
  1338. *                                                                             *
  1339. * Purpose: This procedure verifies that a specified dialog text item is a     *
  1340. *          valid integer, and that it is in the correct range.  If it is      *
  1341. *          invalid, or out or range, the user is informed with a dialog, and  *
  1342. *          FALSE is returned.  Otherwise, FALSE is returned.                  *
  1343. *                                                                             *
  1344. * Parameters: dialog: the dialog which contains the item.                     *
  1345. *             text_item_id: the DITL id of the text item to check             *
  1346. *             label_item_id: the DITL id of the label for this text item      *
  1347. *             min:           the minimum allowable value                      *
  1348. *             max:           the maximum allowable value                      *
  1349. *             returns TRUE if it is valid and in range.                       *
  1350. *                                                                             *
  1351. * Created by: Greg Ferrar                                                     *
  1352. * Created on: September 20, 1992                                              *
  1353. * Modified:                                                                   *
  1354. \*****************************************************************************/
  1355.  
  1356. Boolean is_valid_param_int(DialogPtr dialog, short text_item_id, short label_item_id,
  1357.                         long min, long max)
  1358. {
  1359.  
  1360.     short    type;                /* the item type of a DITL item */
  1361.     Rect    box;                /* the bounding box of a DITL item */
  1362.     Handle    handle;                /* the handle to a DITL item */
  1363.     char    number_string[256];    /* the text of the item */
  1364.     long    number;                /* the number itself */
  1365.     Str255    label;                /* the label for the item */
  1366.     short    item;                /* item hit in ModalDialog call */
  1367.     char    string[256];        /* temporary variable */
  1368.  
  1369.     /* Get the text of the item */
  1370.     GetDItem (dialog, text_item_id, &type, &handle, &box);
  1371.     GetIText (handle, number_string);
  1372.  
  1373.     /* Convert it to a C-style string */
  1374.     PtoCstr(number_string);
  1375.  
  1376.     /* Get the text of the label */
  1377.     GetDItem (dialog, label_item_id, &type, &handle, &box);
  1378.     GetIText (handle, label);
  1379.  
  1380.     /* Chop off the colon at the end of the label */
  1381.     label[0]--;
  1382.  
  1383.     /* Verify that the number is a valid integer */
  1384.     if (!is_valid_int(number_string))
  1385.         {
  1386.         
  1387.         /* Not a valid integer-- notify user */
  1388.         ParamText(label, "\pan integer", 0, 0);
  1389.         ShowWindow(invalid_num_dialog);
  1390.         SelectWindow(invalid_num_dialog);
  1391.         ModalDialog ((ProcPtr) NULL, &item);
  1392.         HideWindow(invalid_num_dialog);
  1393.     
  1394.         /* Tell caller that there was a problem */
  1395.         return FALSE;    
  1396.         }
  1397.  
  1398.     /* Convert it to an integer */
  1399.     StringToNum(CtoPstr(number_string), &number);
  1400.     
  1401.     /* Check it against its upper bound */
  1402.     if (number > max)
  1403.         {
  1404.         
  1405.         /* To large-- notify user */
  1406.         NumToString(max, string);
  1407.         ParamText(label, "\pless than or equal to", string, 0);
  1408.         ShowWindow(param_error_dialog);
  1409.         SelectWindow(param_error_dialog);
  1410.         ModalDialog ((ProcPtr) NULL, &item);
  1411.         HideWindow(param_error_dialog);
  1412.  
  1413.         /* Tell caller that there was a problem */
  1414.         return FALSE;    
  1415.         }
  1416.  
  1417.     /* Check it against its lower bound */
  1418.     if (number < min)
  1419.         {
  1420.         
  1421.         /* To small-- notify user */
  1422.         NumToString(min, string);
  1423.         ParamText(label, "\pgreater than or equal to", string, 0);
  1424.         ShowWindow(param_error_dialog);
  1425.         SelectWindow(param_error_dialog);
  1426.         ModalDialog ((ProcPtr) NULL, &item);
  1427.         HideWindow(param_error_dialog);
  1428.  
  1429.         /* Tell caller that there was a problem */
  1430.         return FALSE;    
  1431.         }
  1432.  
  1433.     /* There was no problem */
  1434.     return TRUE;
  1435.  
  1436. }    /* is_valid_param_int() */
  1437.  
  1438.  
  1439.  
  1440. /*****************************************************************************\
  1441. * procedure is_valid_param_real                                               *
  1442. *                                                                             *
  1443. * Purpose: This procedure verifies that a specified dialog text item is a     *
  1444. *          valid real number, and that it is in the correct range.  If it is  *
  1445. *          invalid, or out or range, the user is informed with a dialog, and  *
  1446. *          FALSE is returned.  Otherwise, TRUE is returned.                   *
  1447. *                                                                             *
  1448. * Parameters: dialog: the dialog which contains the item.                     *
  1449. *             text_item_id: the DITL id of the text item to check             *
  1450. *             label_item_id: the DITL id of the label for this text item      *
  1451. *             min:           the minimum allowable value                      *
  1452. *             max:           the maximum allowable value                      *
  1453. *             include_min:   if this is TRUE, a value of min is acceptable.   *
  1454. *             include_max:   if this is TRUE, a value of max is acceptable.   *
  1455. *             returns TRUE if it is valid and in range.                       *
  1456. *                                                                             *
  1457. * Created by: Greg Ferrar                                                     *
  1458. * Created on: September 20, 1992                                              *
  1459. * Modified:                                                                   *
  1460. \*****************************************************************************/
  1461.  
  1462. Boolean is_valid_param_real(DialogPtr dialog, short text_item_id, short label_item_id,
  1463.                             real min, real max, Boolean include_min, Boolean include_max)
  1464. {
  1465.  
  1466.     short    type;                /* the item type of a DITL item */
  1467.     Rect    box;                /* the bounding box of a DITL item */
  1468.     Handle    handle;                /* the handle to a DITL item */
  1469.     char    number_string[256];    /* the text of the item */
  1470.     real    number;                /* the number itself */
  1471.     Str255    label;                /* the label for the item */
  1472.     short    item;                /* item hit in ModalDialog call */
  1473.     char    string[256];        /* temporary variable */
  1474.  
  1475.     /* Get the text of the item */
  1476.     GetDItem (dialog, text_item_id, &type, &handle, &box);
  1477.     GetIText (handle, number_string);
  1478.  
  1479.     /* Convert it to a C-style string */
  1480.     PtoCstr(number_string);
  1481.  
  1482.     /* Get the text of the label */
  1483.     GetDItem (dialog, label_item_id, &type, &handle, &box);
  1484.     GetIText (handle, label);
  1485.  
  1486.     /* Chop off the colon at the end of the label */
  1487.     label[0]--;
  1488.  
  1489.     /* Verify that the number is a valid real number */
  1490.     if (!is_valid_real(number_string))
  1491.         {
  1492.         
  1493.         /* Not a valid real-- notify user */
  1494.         ParamText(label, "\pa number", 0, 0);
  1495.         ShowWindow(invalid_num_dialog);
  1496.         SelectWindow(invalid_num_dialog);
  1497.         ModalDialog ((ProcPtr) NULL, &item);
  1498.         HideWindow(invalid_num_dialog);
  1499.     
  1500.         /* Tell caller that there was a problem */
  1501.         return FALSE;    
  1502.         }
  1503.  
  1504.     /* Convert it to an real number */
  1505.     number = atof(number_string);
  1506.     
  1507.     /* Check it against its upper bound */
  1508.     if ((number > max) || ((number == max ) && (!include_max)))
  1509.         {
  1510.         
  1511.         /* To large-- notify user */
  1512.  
  1513.         /* Convert max to a string */
  1514.         sprintf(string, "%lg", max);
  1515.  
  1516.         /* Use "less than or equal to" if the max is included; otherwise, just
  1517.             use "less than" */
  1518.         if (include_max)
  1519.             ParamText(label, "\pless than or equal to", CtoPstr(string), 0);
  1520.         else
  1521.             ParamText(label, "\pless than", CtoPstr(string), 0);
  1522.  
  1523.         ShowWindow(param_error_dialog);
  1524.         SelectWindow(param_error_dialog);
  1525.         ModalDialog ((ProcPtr) NULL, &item);
  1526.         HideWindow(param_error_dialog);
  1527.  
  1528.         /* Tell caller that there was a problem */
  1529.         return FALSE;    
  1530.         }
  1531.  
  1532.     /* Check it against its lower bound */
  1533.     if ((number < min) || ((number == min ) && (!include_min)))
  1534.         {
  1535.         
  1536.         /* To small-- notify user */
  1537.         
  1538.         /* Convert min to a string */
  1539.         sprintf(string, "%lg", min);
  1540.  
  1541.         /* Use "greater than or equal to" if the min is included; otherwise, just
  1542.             use "greater than" */
  1543.         if (include_min)
  1544.             ParamText(label, "\pgreater than or equal to", CtoPstr(string), 0);
  1545.         else
  1546.             ParamText(label, "\pgreater than", CtoPstr(string), 0);
  1547.  
  1548.         ShowWindow(param_error_dialog);
  1549.         SelectWindow(param_error_dialog);
  1550.         ModalDialog ((ProcPtr) NULL, &item);
  1551.         HideWindow(param_error_dialog);
  1552.  
  1553.         /* Tell caller that there was a problem */
  1554.         return FALSE;    
  1555.         }
  1556.  
  1557.     /* There was no problem */
  1558.     return TRUE;
  1559.  
  1560. }    /* is_valid_param_real() */
  1561.  
  1562.  
  1563.  
  1564. /*****************************************************************************\
  1565. * procedure is_valid_int                                                      *
  1566. *                                                                             *
  1567. * Purpose: This procedure returns TRUE if the passed string is a valid        *
  1568. *          integer.  If it is not a valid integer, it returns FALSE.          *
  1569. *                                                                             *
  1570. * Parameters: string: the string to check.                                    *
  1571. *             return TRUE if valid.                                           *
  1572. *                                                                             *
  1573. * Created by: Greg Ferrar                                                     *
  1574. * Created on: September 20, 1992                                              *
  1575. * Modified:                                                                   *
  1576. \*****************************************************************************/
  1577.  
  1578. Boolean is_valid_int(char *string)
  1579. {
  1580.  
  1581.     short    i = 0;    /* index */
  1582.     
  1583.     /* accept unary - at beginning */
  1584.     if (string[i] == '-')
  1585.         i++;
  1586.     
  1587.     /* Check that every character is a digit */
  1588.     while (string[i])
  1589.         if (!isdigit(string[i++]))
  1590.             return FALSE;
  1591.     
  1592.     /* All characters are digits */
  1593.     return TRUE;
  1594.  
  1595. }    /* is_valid_int() */
  1596.  
  1597.  
  1598.  
  1599. /*****************************************************************************\
  1600. * procedure is_valid_real                                                     *
  1601. *                                                                             *
  1602. * Purpose: This procedure returns TRUE if the passed string is a valid        *
  1603. *          real number.  If it is not a valid real number, it returns FALSE.  *
  1604. *                                                                             *
  1605. * Parameters: string: the string to check.                                    *
  1606. *             return TRUE if valid.                                           *
  1607. *                                                                             *
  1608. * Created by: Greg Ferrar                                                     *
  1609. * Created on: September 20, 1992                                              *
  1610. * Modified:                                                                   *
  1611. \*****************************************************************************/
  1612.  
  1613. Boolean is_valid_real(char *string)
  1614. {
  1615.  
  1616.     short    i = 0;                    /* index */
  1617.     short    predecimal_length = 0;    /* number of digits before decimal point */
  1618.     short    postdecimal_length = 0;    /* number of digits after decimal point */
  1619.     
  1620.     /* accept unary - at beginning */
  1621.     if (string[i] == '-')
  1622.         i++;
  1623.     
  1624.     /* there should be a sequence of 0 or more digits next */
  1625.     while (isdigit(string[i]))
  1626.         {
  1627.         predecimal_length++;
  1628.         i++;
  1629.         }
  1630.     
  1631.     /* next there could be a decimal point... */
  1632.     if (string[i] == '.')
  1633.         {
  1634.         
  1635.         /* Go to next character */
  1636.         i++;
  1637.         
  1638.         /* Read 0 or more digits after the decimal point */
  1639.         while (isdigit(string[i]))
  1640.             {
  1641.             postdecimal_length++;
  1642.             i++;
  1643.             }
  1644.         
  1645.         }
  1646.     
  1647.     /* If the character after the optional - isn't a digit or a .,
  1648.         OR if there was just a . with no numbers, it's an error */
  1649.     if ((!predecimal_length) && (!postdecimal_length))
  1650.         return FALSE;
  1651.         
  1652.     /* If we get this far, we know we have a number with an optional unary -,
  1653.         followed by a valid mantissa */
  1654.     
  1655.     /* next there could be an exponent */
  1656.     if ((string[i] == 'e') || (string[i] == 'E'))
  1657.         {
  1658.         
  1659.         /* Go to next token */
  1660.         i++;
  1661.         
  1662.         /* there could be an unary - before the exponent */
  1663.         if (string[i] == '-')
  1664.             i++;
  1665.  
  1666.         /* Read 1 or more digits after the exponent point */
  1667.         if (!isdigit(string[i]))
  1668.             return FALSE;    /* error- no digits in exponent */
  1669.         do
  1670.             i++;
  1671.         while (isdigit(string[i]));
  1672.         
  1673.         }
  1674.     
  1675.     /* That's all folks-- anything else is illegal */
  1676.     if (string[i])
  1677.         return FALSE;
  1678.     
  1679.     /* no error encountered */
  1680.     return TRUE;
  1681.     
  1682. }    /* is_valid_real() */
  1683.  
  1684.  
  1685.  
  1686. /*****************************************************************************\
  1687. * procedure load_popup_menus                                                  *
  1688. *                                                                             *
  1689. * Purpose: This procedure loads the popup menus from the resource file and    *
  1690. *          installs hooks in the MenuProcs so that they will be wide enough,  *
  1691. *          when popped up, to accommodate the down arrow.                     *
  1692. *                                                                             *
  1693. * Created by: Greg Ferrar                                                     *
  1694. * Created on: August 21, 1992                                                 *
  1695. * Modified:                                                                   *
  1696. \*****************************************************************************/
  1697.  
  1698. void load_popup_menus(void)
  1699. {
  1700.  
  1701.     antialiasing_menu = GetMenu (ANTIALIASING_MENU);
  1702.     install_popup_menu_hook(antialiasing_menu);
  1703.     lighting_menu = GetMenu (LIGHTING_MENU);
  1704.     install_popup_menu_hook(lighting_menu);
  1705.     normal_menu = GetMenu (NORMAL_MENU);
  1706.     install_popup_menu_hook(normal_menu);
  1707.     intersect_menu = GetMenu (INTERSECT_MENU);
  1708.     install_popup_menu_hook(intersect_menu);
  1709.     texture_menu = GetMenu (TEXTURE_MENU);
  1710.     install_popup_menu_hook(texture_menu);
  1711.     shading_menu = GetMenu (SHADING_MENU);
  1712.     install_popup_menu_hook(shading_menu);
  1713.     view_menu = GetMenu (VIEW_MENU);
  1714.     install_popup_menu_hook(view_menu);
  1715.     stereo_separation_menu = GetMenu (STEREO_SEPARATION_MENU);
  1716.     install_popup_menu_hook(stereo_separation_menu);
  1717.     sampling_level_menu = GetMenu (SAMPLING_LEVEL_MENU);
  1718.     install_popup_menu_hook(sampling_level_menu);
  1719.     save_file_type_menu = GetMenu (SAVE_FILE_TYPE_MENU);
  1720.     install_popup_menu_hook(save_file_type_menu);
  1721.     save_anim_file_type_menu = GetMenu (SAVE_ANIM_FILE_TYPE_MENU);
  1722.     install_popup_menu_hook(save_anim_file_type_menu);
  1723.  
  1724. }    /* load_popup_menus() */
  1725.  
  1726.  
  1727.  
  1728. /*****************************************************************************\
  1729. * procedure setup_check_boxes                                                 *
  1730. *                                                                             *
  1731. * Purpose: This procedure loads in the check box controls for the dialog      *
  1732. *          boxes.  It saves the handles for later manipulation.               *
  1733. *                                                                             *
  1734. * Created by: Greg Ferrar                                                     *
  1735. * Created on: August 2, 1992                                                  *
  1736. * Modified:                                                                   *
  1737. \*****************************************************************************/
  1738.  
  1739. void setup_check_boxes(void)
  1740. {
  1741.  
  1742.     short    type;        /* the item type of a DITL item */
  1743.     Rect    box;        /* the bounding box of a DITL item */
  1744.  
  1745.     /* Load the check box handles into memory */
  1746.     GetDItem (options_dialog, INTERSECT_ADJUST_CHECKBOX, &type,
  1747.                 &intersect_adjust_checkbox, &box);
  1748.     GetDItem (options_dialog, USE_JITTERED_SAMPLE_CHECKBOX, &type,
  1749.                 &use_jittered_sample_checkbox, &box);
  1750.     GetDItem (options_dialog, SPECIFY_FOCAL_DISTANCE_CHECKBOX, &type,
  1751.                 &specify_focal_distance_checkbox, &box);
  1752.     GetDItem (options_dialog, CORRECT_TEXTURE_NORMAL_CHECKBOX, &type,
  1753.                 &correct_texture_normal_checkbox, &box);
  1754.     GetDItem (options_dialog, SPECIFY_FOCAL_DISTANCE_CHECKBOX, &type,
  1755.                 &specify_focal_distance_checkbox, &box);
  1756.     GetDItem (options_dialog, ANIMATE_CHECKBOX, &type,
  1757.                 &animate_checkbox, &box);
  1758.     GetDItem (preferences_dialog, ALLOW_BACKGROUND_TASKS_CHECKBOX, &type,
  1759.                 &allow_background_tasks_checkbox, &box);
  1760.     GetDItem (preferences_dialog, SHOW_IMAGE_RENDERING_CHECKBOX, &type,
  1761.                 &show_image_rendering_checkbox, &box);
  1762.     GetDItem (preferences_dialog, KEEP_IMAGE_IN_MEMORY_CHECKBOX, &type,
  1763.                 &keep_image_in_memory_checkbox, &box);
  1764.     GetDItem (preferences_dialog, SHOW_STATUS_WINDOW_CHECKBOX, &type,
  1765.                 &show_status_window_checkbox, &box);
  1766.     GetDItem (preferences_dialog, SHOW_ABOUT_WINDOW_CHECKBOX, &type,
  1767.                 &show_about_window_checkbox, &box);
  1768.     GetDItem (preferences_dialog, HIDE_OPTIONS_WINDOW_CHECKBOX, &type,
  1769.                 &hide_options_window_checkbox, &box);
  1770.  
  1771. }    /* setup_check_boxes() */
  1772.  
  1773.  
  1774.  
  1775. /*****************************************************************************\
  1776. * procedure setup_useritems                                                   *
  1777. *                                                                             *
  1778. * Purpose: This procedure sets up the user items in the dialog boxes.         *
  1779. *          These user item are used to implement the popup menus, the         *
  1780. *          border around the default button, and the dimming of the "Focal    *
  1781. *          distance text.                                                     *
  1782. *                                                                             *
  1783. * Created by: Greg Ferrar                                                     *
  1784. * Created on: August 21, 1992                                                 *
  1785. * Modified:                                                                   *
  1786. \*****************************************************************************/
  1787.  
  1788. void setup_useritems(void)
  1789. {
  1790.  
  1791.     short    item_type;        /* the item type of a DITL item */
  1792.     Handle    item_handle;    /* a handle to a DITL item */
  1793.     Rect    item_box;        /* the bounding box of a DITL item */
  1794.  
  1795.     /* Set up the border around the default button in the options dialog */
  1796.     GetDItem (options_dialog, BUTTON_BORDER_USERITEM, &item_type, &item_handle, &item_box);
  1797.     SetDItem (options_dialog, BUTTON_BORDER_USERITEM, item_type, draw_button_border, &item_box);
  1798.  
  1799.     /* Set up the border around the default button in the preferences dialog */
  1800.     GetDItem (preferences_dialog, PREF_BUTTON_BORDER_USERITEM,
  1801.                 &item_type, &item_handle, &item_box);
  1802.     SetDItem (preferences_dialog, PREF_BUTTON_BORDER_USERITEM,
  1803.                 item_type, draw_button_border, &item_box);
  1804.  
  1805.     /* Set up the border around the default button in the animation dialog */
  1806.     GetDItem (animation_dialog, BUTTON_BORDER_USERITEM, &item_type, &item_handle, &item_box);
  1807.     SetDItem (animation_dialog, BUTTON_BORDER_USERITEM, item_type, draw_button_border, &item_box);
  1808.  
  1809.     /* Set up the border around the default button in the about dialog */
  1810.     GetDItem (about_dialog, ABOUT_BUTTON_BORDER_USERITEM, &item_type, &item_handle, &item_box);
  1811.     SetDItem (about_dialog, ABOUT_BUTTON_BORDER_USERITEM,
  1812.                 item_type, draw_button_border, &item_box);
  1813.  
  1814.     /* Set up the border around the default button in the Cancel dialog */
  1815.     GetDItem (cancel_dialog, CANCEL_FRAME_BUTTON_USERITEM, &item_type, &item_handle, &item_box);
  1816.     SetDItem (cancel_dialog, CANCEL_FRAME_BUTTON_USERITEM,
  1817.                 item_type, draw_button_border, &item_box);
  1818.  
  1819.     /* Set up the border around the default button in the Abort Render dialog */
  1820.     GetDItem (abort_render_dialog, ABORT_RENDER_FRAME_BUTTON_USERITEM,
  1821.                 &item_type, &item_handle, &item_box);
  1822.     SetDItem (abort_render_dialog, ABORT_RENDER_FRAME_BUTTON_USERITEM,
  1823.                 item_type, draw_button_border, &item_box);
  1824.  
  1825.     /* Set up the border around the default button in the Parameter Error dialog */
  1826.     GetDItem (param_error_dialog, BUTTON_BORDER_USERITEM, &item_type, &item_handle, &item_box);
  1827.     SetDItem (param_error_dialog, BUTTON_BORDER_USERITEM,
  1828.                 item_type, draw_button_border, &item_box);
  1829.  
  1830.     /* Set up the border around the default button in the Prompt to Save dialog */
  1831.     GetDItem (prompt_save_dialog, BUTTON_BORDER_USERITEM, &item_type, &item_handle, &item_box);
  1832.     SetDItem (prompt_save_dialog, BUTTON_BORDER_USERITEM,
  1833.                 item_type, draw_button_border, &item_box);
  1834.  
  1835.     /* Set up the border around the default button in the Invalid Number Error dialog */
  1836.     GetDItem (invalid_num_dialog, BUTTON_BORDER_USERITEM, &item_type, &item_handle, &item_box);
  1837.     SetDItem (invalid_num_dialog, BUTTON_BORDER_USERITEM,
  1838.                 item_type, draw_button_border, &item_box);
  1839.  
  1840.     /* Set up the picture useritems in the About... dialog */
  1841.     GetDItem (about_dialog, ABOUT_PICT_USERITEM, &item_type, &item_handle, &item_box);
  1842.     SetDItem (about_dialog, ABOUT_PICT_USERITEM, item_type, draw_about_picture, &item_box);
  1843.     GetDItem (about_dialog, ABOUT_TEXT_PICT_USERITEM, &item_type, &item_handle,
  1844.                 &about_rtrace_image_bounds);
  1845.     SetDItem (about_dialog, ABOUT_TEXT_PICT_USERITEM, item_type, draw_about_text_picture,
  1846.                 &about_rtrace_image_bounds);
  1847.     GetDItem (about_dialog, ABOUT_CREDITS_PICT_USERITEM, &item_type, &item_handle, &item_box);
  1848.     SetDItem (about_dialog, ABOUT_CREDITS_PICT_USERITEM, item_type,
  1849.                 draw_about_credits_picture, &item_box);
  1850.     
  1851.     /* Set up the progress bar in the status dialog */
  1852.     GetDItem (status_dialog, PROGRESS_BAR_USERITEM, &item_type, &item_handle, &item_box);
  1853.     SetDItem (status_dialog, PROGRESS_BAR_USERITEM, item_type, draw_progress_bar, &item_box);
  1854.     progress_bar_length = item_box.right - item_box.left - 2;
  1855.  
  1856.     /* Set up the sub-progress bar in the status dialog */
  1857.     GetDItem (status_dialog, SUB_PROGRESS_BAR_USERITEM, &item_type, &item_handle, &item_box);
  1858.     SetDItem (status_dialog, SUB_PROGRESS_BAR_USERITEM, item_type, draw_sub_progress_bar, &item_box);
  1859.     sub_progress_bar_length = item_box.right - item_box.left - 2;
  1860.  
  1861.     /* Set up the dimming of the focal distance text */
  1862.     GetDItem (options_dialog, DIM_FOCAL_DISTANCE_USERITEM, &item_type, &item_handle, &item_box);
  1863.     SetDItem (options_dialog, DIM_FOCAL_DISTANCE_USERITEM, item_type, dim_focal_distance, &item_box);
  1864.  
  1865.     /* Set up the dimming of the stereo separation items */
  1866.     GetDItem (options_dialog, DIM_STEREO_SEPARATION_USERITEM, &item_type, &item_handle, &item_box);
  1867.     SetDItem (options_dialog, DIM_STEREO_SEPARATION_USERITEM, userItem, dim_stereo_separation, &item_box);
  1868.  
  1869.     /* Set up the dimming of the relinquish control items */
  1870.     GetDItem (preferences_dialog, DIM_ALLOW_BACKGROUND_TASKS_USERITEM, &item_type,
  1871.                 &item_handle, &item_box);
  1872.     SetDItem (preferences_dialog, DIM_ALLOW_BACKGROUND_TASKS_USERITEM, userItem,
  1873.                 dim_relinquish_control, &item_box);
  1874.  
  1875.     /* Set up the dimming of the Keep Image In Memory checkbox */
  1876.     GetDItem (preferences_dialog, DIM_KEEP_IMAGE_IN_MEMORY_USERITEM, &item_type,
  1877.                 &item_handle, &item_box);
  1878.     SetDItem (preferences_dialog, DIM_KEEP_IMAGE_IN_MEMORY_USERITEM, userItem,
  1879.                 dim_keep_image_in_memory, &item_box);
  1880.  
  1881.     /* Set up the dimming of the Show Image Rendering checkbox */
  1882.     GetDItem (preferences_dialog, DIM_SHOW_IMAGE_RENDERING_USERITEM, &item_type,
  1883.                 &item_handle, &item_box);
  1884.     SetDItem (preferences_dialog, DIM_SHOW_IMAGE_RENDERING_USERITEM, userItem,
  1885.                 dim_show_image_rendering, &item_box);
  1886.  
  1887.     /* Set up the dimming of the aliasing threshold items */
  1888.     GetDItem (options_dialog, DIM_ALIASING_THRESHOLD_USERITEM, &item_type, &item_handle, &item_box);
  1889.     SetDItem (options_dialog, DIM_ALIASING_THRESHOLD_USERITEM, userItem, dim_aliasing_threshold, &item_box);
  1890.  
  1891.     /* Set up antialiasing popup menu */
  1892.     setup_popup_menu (ANTIALIASING_POPUP, draw_antialiasing_popup);
  1893.  
  1894.     /* Set up lighting popup menu */
  1895.     setup_popup_menu (LIGHTING_POPUP, draw_lighting_popup);
  1896.  
  1897.     /* Set up normal popup menu */
  1898.     setup_popup_menu (NORMAL_POPUP, draw_normal_popup);
  1899.                 
  1900.     /* Set up intersect popup menu */
  1901.     setup_popup_menu (INTERSECT_POPUP, draw_intersect_popup);
  1902.                 
  1903.     /* Set up texture popup menu */
  1904.     setup_popup_menu (TEXTURE_POPUP, draw_texture_popup);
  1905.                 
  1906.     /* Set up view popup menu */
  1907.     setup_popup_menu (VIEW_POPUP, draw_view_popup);
  1908.                 
  1909.     /* Set up stereo separation popup menu */
  1910.     setup_popup_menu (STEREO_SEPARATION_POPUP, draw_stereo_separation_popup);
  1911.  
  1912.     /* Set up sampling level popup menu */
  1913.     setup_popup_menu (SAMPLING_LEVEL_POPUP, draw_sampling_level_popup);
  1914.  
  1915.     /* Set up shading popup menu */
  1916.     setup_popup_menu (SHADING_POPUP, draw_shading_popup);
  1917.  
  1918.     /* Get the handle to the Render button */
  1919.     GetDItem (options_dialog, RENDER_BUTTON, &item_type, &render_button_handle,
  1920.                 &item_box);
  1921.  
  1922.     /* Get the handle to the Okay button in the animation dialog */
  1923.     GetDItem (animation_dialog, OKAY_BUTTON, &item_type, &animation_okay_button_handle,
  1924.                 &item_box);
  1925.  
  1926.     /* Get the handle to the Okay button in the preferences dialog */
  1927.     GetDItem (preferences_dialog, OKAY_BUTTON, &item_type, &preferences_okay_button_handle,
  1928.                 &item_box);
  1929.  
  1930.     /* Get the handle to the More button in the about dialog */
  1931.     GetDItem (about_dialog, MORE_BUTTON, &item_type, &about_more_button_handle,
  1932.                 &item_box);
  1933.  
  1934. }    /* setup_useritems() */
  1935.  
  1936.  
  1937.  
  1938. /*****************************************************************************\
  1939. * procedure setup_popup_menu                                                  *
  1940. *                                                                             *
  1941. * Purpose: This procedure sets up a popup menu in the options dialog box.     *
  1942. *                                                                             *
  1943. * Parameters: useritem_id: the ID of the useritem which is the bounding box   *
  1944. *                          of the popup menu.                                 *
  1945. *             proc:        the procedure to draw the useritem (called by the  *
  1946. *                          Dialog Manager).                                   *
  1947. *             upper_left:  the upper left corner of the popup menu.           *
  1948. *                                                                             *
  1949. * Created by: Greg Ferrar                                                     *
  1950. * Created on: August 21, 1992                                                 *
  1951. * Modified:                                                                   *
  1952. \*****************************************************************************/
  1953.  
  1954. void setup_popup_menu (short useritem_id, UserItemProc *proc)
  1955. {
  1956.  
  1957.     short    item_type;        /* the item type of a DITL item */
  1958.     Handle    item_handle;    /* a handle to a DITL item */
  1959.     Rect    item_box;        /* the bounding box of a DITL item */
  1960.  
  1961.     /* Set up the popup menu */
  1962.     GetDItem (options_dialog, useritem_id, &item_type, &item_handle, &item_box);
  1963.     SetDItem (options_dialog, useritem_id, userItem, proc, &item_box);
  1964.  
  1965. }    /* setup_popup_menu() */
  1966.  
  1967.  
  1968.  
  1969. /*****************************************************************************\
  1970. * procedure draw_button_border                                                *
  1971. *                                                                             *
  1972. * Purpose: This procedure draws the border around the default button in a     *
  1973. *          dialog.                                                            *
  1974. *                                                                             *
  1975. * Parameters: all ignored                                                     *
  1976. *                                                                             *
  1977. * Created by: Greg Ferrar                                                     *
  1978. * Created on: August 21, 1992                                                 *
  1979. * Modified:                                                                   *
  1980. \*****************************************************************************/
  1981.  
  1982. pascal void draw_button_border (WindowPtr the_window, short item_number)
  1983. {
  1984.  
  1985.     short    item_type;        /* the item type of a DITL item */
  1986.     Handle    item_handle;    /* a handle to a DITL item */
  1987.     Rect    item_box;        /* the bounding box of a DITL item */
  1988.  
  1989.     /* draw the outline */
  1990.     GetDItem (the_window, OKAY_BUTTON, &item_type, &item_handle,
  1991.                 &item_box);
  1992.     PenSize(3, 3);
  1993.     InsetRect (&item_box, -4, -4);
  1994.     FrameRoundRect (&item_box, 16, 16);
  1995.     PenSize(1, 1);
  1996.  
  1997. }    /* draw_button_border() */
  1998.  
  1999.  
  2000.  
  2001. /*****************************************************************************\
  2002. * procedure draw_about_picture                                                *
  2003. *                                                                             *
  2004. * Purpose: This procedure draws the picture in the about dialog.              *
  2005. *                                                                             *
  2006. * Parameters: all ignored                                                     *
  2007. *                                                                             *
  2008. * Created by: Greg Ferrar                                                     *
  2009. * Created on: September 15, 1992                                              *
  2010. * Modified:                                                                   *
  2011. \*****************************************************************************/
  2012.  
  2013. pascal void draw_about_picture (WindowPtr the_window, short item_number)
  2014. {
  2015.  
  2016.     short    item_type;        /* the item type of a DITL item */
  2017.     Handle    item_handle;    /* a handle to a DITL item */
  2018.     Rect    item_box;        /* the bounding box of a DITL item */
  2019.  
  2020.     /* Find the rectangle */
  2021.     GetDItem (the_window, ABOUT_PICT_USERITEM, &item_type, &item_handle,
  2022.                 &item_box);
  2023.  
  2024.     /* Draw the picture in the rectangle */
  2025.     DrawPicture (about_picture, &item_box);
  2026.  
  2027. }    /* draw_about_picture() */
  2028.  
  2029.  
  2030.  
  2031. /*****************************************************************************\
  2032. * procedure draw_about_text_picture                                           *
  2033. *                                                                             *
  2034. * Purpose: This procedure draws the text picture in the about dialog.         *
  2035. *                                                                             *
  2036. * Parameters: all ignored                                                     *
  2037. *                                                                             *
  2038. * Created by: Greg Ferrar                                                     *
  2039. * Created on: September 15, 1992                                              *
  2040. * Modified:                                                                   *
  2041. \*****************************************************************************/
  2042.  
  2043. pascal void draw_about_text_picture (WindowPtr the_window, short item_number)
  2044. {
  2045.  
  2046.     short    item_type;        /* the item type of a DITL item */
  2047.     Handle    item_handle;    /* a handle to a DITL item */
  2048.     Rect    item_box;        /* the bounding box of a DITL item */
  2049.  
  2050.     /* Find the rectangle */
  2051.     GetDItem (the_window, ABOUT_TEXT_PICT_USERITEM, &item_type, &item_handle,
  2052.                 &item_box);
  2053.  
  2054.     /* Draw the picture in the rectangle */
  2055.     DrawPicture (about_text_picture, &item_box);
  2056.  
  2057. }    /* draw_about_text_picture() */
  2058.  
  2059.  
  2060.  
  2061. /*****************************************************************************\
  2062. * procedure draw_about_credits_picture                                        *
  2063. *                                                                             *
  2064. * Purpose: This procedure draws the credits picture in the about dialog.      *
  2065. *                                                                             *
  2066. * Parameters: all ignored                                                     *
  2067. *                                                                             *
  2068. * Created by: Greg Ferrar                                                     *
  2069. * Created on: September 15, 1992                                              *
  2070. * Modified:                                                                   *
  2071. \*****************************************************************************/
  2072.  
  2073. pascal void draw_about_credits_picture (WindowPtr the_window, short item_number)
  2074. {
  2075.  
  2076.     short    item_type;        /* the item type of a DITL item */
  2077.     Handle    item_handle;    /* a handle to a DITL item */
  2078.     Rect    item_box;        /* the bounding box of a DITL item */
  2079.  
  2080.     /* Find the rectangle */
  2081.     GetDItem (the_window, ABOUT_CREDITS_PICT_USERITEM, &item_type, &item_handle,
  2082.                 &item_box);
  2083.  
  2084.     /* Draw the picture in the rectangle */
  2085.     DrawPicture (about_credits_picture, &item_box);
  2086.  
  2087. }    /* draw_about_credits_picture() */
  2088.  
  2089.  
  2090.  
  2091. /*****************************************************************************\
  2092. * procedure draw_progress_bar                                                 *
  2093. *                                                                             *
  2094. * Purpose: This procedure draws the progress bar in the status dialog.        *
  2095. *                                                                             *
  2096. * Parameters: all ignored                                                     *
  2097. *                                                                             *
  2098. * Created by: Greg Ferrar                                                     *
  2099. * Created on: September 3, 1992                                               *
  2100. * Modified:                                                                   *
  2101. \*****************************************************************************/
  2102.  
  2103. pascal void draw_progress_bar (WindowPtr the_window, short item_number)
  2104. {
  2105.  
  2106.     int                type;
  2107.     Handle            item;
  2108.     Rect            box;
  2109.     
  2110.  
  2111.     /* Find the new length of the filled part of the bar */
  2112.     progress_bar_dividing_line = (progress_bar_length * progress_bar_value)/progress_bar_max;
  2113.     
  2114.     /* Set the port to draw in the status dialog */
  2115.     SetPort (status_dialog);
  2116.     
  2117.     /* get the outline of the bar */
  2118.     GetDItem (status_dialog, PROGRESS_BAR_USERITEM, &type, &item, &box);
  2119.     
  2120.     /* outline the bar */
  2121.     FrameRect (&box);
  2122.     
  2123.     /* Get the interior of the bar */
  2124.     InsetRect (&box, 1, 1);
  2125.  
  2126.     /* If Color QuickDraw is available, color the filled part solid dark gray */
  2127.     if (f8bit_QD_available)
  2128.         RGBForeColor (&bar_gray);
  2129.         
  2130.     /* Otherwise, use Original QD dithered gray */
  2131.     else
  2132.         PenPat (gray);
  2133.  
  2134.     /* Shade the filled part */
  2135.     box.right = box.left + progress_bar_dividing_line;
  2136.     PaintRect(&box);
  2137.     
  2138.     /* If Color QuickDraw is available, color the empty part light blue */
  2139.     if (f8bit_QD_available)
  2140.         RGBForeColor (&bar_blue);
  2141.  
  2142.     /* Otherwise, use Original QD white */
  2143.     else
  2144.         PenPat (white);
  2145.  
  2146.     /* Erase the unfilled part */
  2147.     box.right = box.left + progress_bar_length;
  2148.     box.left += progress_bar_dividing_line;
  2149.     PaintRect (&box);
  2150.  
  2151.     /* Restore the foreground color to normal */
  2152.     if (f8bit_QD_available)
  2153.         RGBForeColor (&bar_black);
  2154.     else
  2155.         PenPat(&black);
  2156.  
  2157. }    /* draw_progress_bar() */
  2158.  
  2159.  
  2160.  
  2161. /*****************************************************************************\
  2162. * procedure update_progress_bar                                               *
  2163. *                                                                             *
  2164. * Purpose: This procedure draws the progress bar in the status dialog, but    *
  2165. *          only if it has changed since last drawing.                         *
  2166. *                                                                             *
  2167. * Created by: Greg Ferrar                                                     *
  2168. * Created on: September 3, 1992                                               *
  2169. * Modified:                                                                   *
  2170. \*****************************************************************************/
  2171.  
  2172. void update_progress_bar (void)
  2173. {
  2174.  
  2175.     /* Draw the bar if its appearance has changed */
  2176.     if (progress_bar_dividing_line != 
  2177.             (progress_bar_length * progress_bar_value)/progress_bar_max)
  2178.     
  2179.         draw_progress_bar(status_dialog, PROGRESS_BAR_USERITEM);
  2180.     
  2181. }    /* update_progress_bar() */
  2182.  
  2183.  
  2184.  
  2185. /*****************************************************************************\
  2186. * procedure draw_sub_progress_bar                                             *
  2187. *                                                                             *
  2188. * Purpose: This procedure draws the sub-progress bar in the status dialog.    *
  2189. *                                                                             *
  2190. * Parameters: all ignored                                                     *
  2191. *                                                                             *
  2192. * Created by: Greg Ferrar                                                     *
  2193. * Created on: September 3, 1992                                               *
  2194. * Modified:                                                                   *
  2195. \*****************************************************************************/
  2196.  
  2197. pascal void draw_sub_progress_bar (WindowPtr the_window, short item_number)
  2198. {
  2199.  
  2200.     int                type;
  2201.     Handle            item;
  2202.     Rect            box;
  2203.     
  2204.     /* Find the new length of the filled part of the bar */
  2205.     sub_progress_bar_dividing_line =
  2206.                 (sub_progress_bar_length * sub_progress_bar_value)/sub_progress_bar_max;
  2207.     
  2208.     /* Set the port to draw in the status dialog */
  2209.     SetPort (status_dialog);
  2210.     
  2211.     /* get the outline of the bar */
  2212.     GetDItem (status_dialog, SUB_PROGRESS_BAR_USERITEM, &type, &item, &box);
  2213.     
  2214.     /* outline the bar */
  2215.     FrameRect (&box);
  2216.     
  2217.     /* Get the interior of the bar */
  2218.     InsetRect (&box, 1, 1);
  2219.  
  2220.     /* If Color QuickDraw is available, color the filled part solid dark gray */
  2221.     if (f8bit_QD_available)
  2222.         RGBForeColor (&bar_gray);
  2223.         
  2224.     /* Otherwise, use Original QD dithered gray */
  2225.     else
  2226.         PenPat (gray);
  2227.  
  2228.     /* Shade the filled part */
  2229.     box.right = box.left + sub_progress_bar_dividing_line;
  2230.     PaintRect(&box);
  2231.     
  2232.     /* If Color QuickDraw is available, color the empty part light blue */
  2233.     if (f8bit_QD_available)
  2234.         RGBForeColor (&bar_blue);
  2235.  
  2236.     /* Otherwise, use Original QD white */
  2237.     else
  2238.         PenPat (white);
  2239.  
  2240.     /* Erase the unfilled part */
  2241.     box.right = box.left + sub_progress_bar_length;
  2242.     box.left += sub_progress_bar_dividing_line;
  2243.     PaintRect (&box);
  2244.  
  2245.     /* Restore the foreground color to normal */
  2246.     if (f8bit_QD_available)
  2247.         RGBForeColor (&bar_black);
  2248.     else
  2249.         PenPat(&black);
  2250.  
  2251. }    /* draw_sub_progress_bar() */
  2252.  
  2253.  
  2254.  
  2255. /*****************************************************************************\
  2256. * procedure update_sub_progress_bar                                           *
  2257. *                                                                             *
  2258. * Purpose: This procedure draws the sub-progress bar in the status dialog,    *
  2259. *          but only if it has changed since last drawing.                     *
  2260. *                                                                             *
  2261. * Created by: Greg Ferrar                                                     *
  2262. * Created on: September 4, 1992                                               *
  2263. * Modified:                                                                   *
  2264. \*****************************************************************************/
  2265.  
  2266. void update_sub_progress_bar (void)
  2267. {
  2268.  
  2269.     /* Draw the bar if its appearance has changed */
  2270.     if (sub_progress_bar_dividing_line != 
  2271.             (sub_progress_bar_length * sub_progress_bar_value)/sub_progress_bar_max)
  2272.     
  2273.         draw_sub_progress_bar(status_dialog, SUB_PROGRESS_BAR_USERITEM);
  2274.     
  2275. }    /* update_sub_progress_bar() */
  2276.  
  2277.  
  2278.  
  2279. /*****************************************************************************\
  2280. * procedure update_status_free_memory                                         *
  2281. *                                                                             *
  2282. * Purpose: This procedure updates the amount of free memory shown in the      *
  2283. *          status dialog.                                                     *
  2284. *                                                                             *
  2285. * Created by: Greg Ferrar                                                     *
  2286. * Created on: September 3, 1992                                               *
  2287. * Modified:                                                                   *
  2288. \*****************************************************************************/
  2289.  
  2290. void update_status_free_memory (void)
  2291. {
  2292.  
  2293.     long    free_mem;
  2294.     Str255    free_mem_string;
  2295.  
  2296.     /* Get the number of K free as a string */
  2297.     free_mem = FreeMem();
  2298.     free_mem /= 1024;
  2299.     NumToString (free_mem, free_mem_string);
  2300.     
  2301.     /* Add 'K' to the end */
  2302.     free_mem_string[0]++;
  2303.     free_mem_string[free_mem_string[0]] = 'K';
  2304.  
  2305.     /* Change the text of the dialog to reflect the current amount of memory */
  2306.     set_dialog_text(status_dialog, FREE_MEMORY_NUM, free_mem_string);
  2307.  
  2308. }    /* update_status_free_memory() */
  2309.  
  2310.  
  2311.  
  2312. /*****************************************************************************\
  2313. * procedure set_status_image_data_size                                        *
  2314. *                                                                             *
  2315. * Purpose: This procedure updates the image data size text in the status      *
  2316. *          dialog.                                                            *
  2317. *                                                                             *
  2318. * Parameters: size: the new image data size                                   *
  2319. *                                                                             *
  2320. * Created by: Greg Ferrar                                                     *
  2321. * Created on: September 3, 1992                                               *
  2322. * Modified:                                                                   *
  2323. \*****************************************************************************/
  2324.  
  2325. void set_status_image_data_size (long size)
  2326. {
  2327.  
  2328.     Str255    image_size_string;
  2329.  
  2330.     /* Get the number of K free as a string */
  2331.     NumToString (size/1024L, image_size_string);
  2332.     
  2333.     /* Add 'K' to the end */
  2334.     image_size_string[0]++;
  2335.     image_size_string[image_size_string[0]] = 'K';
  2336.  
  2337.     /* Change the text of the dialog to reflect the current amount of memory */
  2338.     set_dialog_text(status_dialog, IMAGE_MEMORY_NUM, image_size_string);
  2339.  
  2340. }    /* set_status_image_data_size() */
  2341.  
  2342.  
  2343.  
  2344. /*****************************************************************************\
  2345. * procedure set_status_text                                                   *
  2346. *                                                                             *
  2347. * Purpose: This procedure sets the status text in the status dialog.          *
  2348. *                                                                             *
  2349. * Parameters: string: the text to use                                         *
  2350. *                                                                             *
  2351. * Created by: Greg Ferrar                                                     *
  2352. * Created on: September 3, 1992                                               *
  2353. * Modified:                                                                   *
  2354. \*****************************************************************************/
  2355.  
  2356. void set_status_text(Str255 string)
  2357. {
  2358.  
  2359.     /* set the text */
  2360.     set_dialog_text(status_dialog, STATUS_TEXT, string);
  2361.  
  2362. }    /* set_status_text() */
  2363.  
  2364.  
  2365.  
  2366. /*****************************************************************************\
  2367. * procedure set_status_num_objects                                            *
  2368. *                                                                             *
  2369. * Purpose: This procedure sets number of objects text in the status dialog.   *
  2370. *                                                                             *
  2371. * Parameters: num_objects: the new number of objects                          *
  2372. *                                                                             *
  2373. * Created by: Greg Ferrar                                                     *
  2374. * Created on: September 3, 1992                                               *
  2375. * Modified:                                                                   *
  2376. \*****************************************************************************/
  2377.  
  2378. void set_status_num_objects(long num_objects)
  2379. {
  2380.  
  2381.     /* set the number of objects text */
  2382.     set_dialog_num(status_dialog, NUM_OBJECTS_NUM, num_objects);
  2383.  
  2384. }    /* set_status_num_objects() */
  2385.  
  2386.  
  2387.  
  2388. /*****************************************************************************\
  2389. * procedure set_progress_bar_value                                            *
  2390. *                                                                             *
  2391. * Purpose: This procedure sets the value of the progress bar in the status    *
  2392. *          dialog, and redraws the progress bar.                              *
  2393. *                                                                             *
  2394. * Parameters: value: the new progress bar value                               *
  2395. *                                                                             *
  2396. * Created by: Greg Ferrar                                                     *
  2397. * Created on: September 3, 1992                                               *
  2398. * Modified:                                                                   *
  2399. \*****************************************************************************/
  2400.  
  2401. void set_progress_bar_value(long value)
  2402. {
  2403.  
  2404.     /* Set the bar to the new value */
  2405.     progress_bar_value = value;
  2406.  
  2407.     /* update the progress bar */
  2408.     update_progress_bar();
  2409.  
  2410. }    /* set_progress_bar_value() */
  2411.  
  2412.  
  2413.  
  2414. /*****************************************************************************\
  2415. * procedure set_progress_bar_max                                              *
  2416. *                                                                             *
  2417. * Purpose: This procedure sets the maximum value of the progress bar in the   *
  2418. *          status dialog.  It does not redraw the progress bar.               *
  2419. *                                                                             *
  2420. * Parameters: value: the new progress bar value                               *
  2421. *                                                                             *
  2422. * Created by: Greg Ferrar                                                     *
  2423. * Created on: September 3, 1992                                               *
  2424. * Modified:                                                                   *
  2425. \*****************************************************************************/
  2426.  
  2427. void set_progress_bar_max(long value)
  2428. {
  2429.  
  2430.     /* Set the bar to the new value */
  2431.     progress_bar_max = value;
  2432.  
  2433. }    /* set_progress_bar_max() */
  2434.  
  2435.  
  2436.  
  2437. /*****************************************************************************\
  2438. * procedure set_sub_progress_bar_value                                        *
  2439. *                                                                             *
  2440. * Purpose: This procedure sets the value of the sub-progress bar in the       *
  2441. *          status dialog, and redraws the sub-progress bar.                   *
  2442. *                                                                             *
  2443. * Parameters: value: the new sub-progress bar value                           *
  2444. *                                                                             *
  2445. * Created by: Greg Ferrar                                                     *
  2446. * Created on: September 4, 1992                                               *
  2447. * Modified:                                                                   *
  2448. \*****************************************************************************/
  2449.  
  2450. void set_sub_progress_bar_value(long value)
  2451. {
  2452.  
  2453.     /* Set the bar to the new value */
  2454.     sub_progress_bar_value = value;
  2455.  
  2456.     /* update the sub-progress bar */
  2457.     update_sub_progress_bar();
  2458.  
  2459. }    /* set_sub_progress_bar_value() */
  2460.  
  2461.  
  2462.  
  2463. /*****************************************************************************\
  2464. * procedure set_sub_progress_bar_max                                          *
  2465. *                                                                             *
  2466. * Purpose: This procedure sets the maximum value of the sub-progress bar in   *
  2467. *          the status dialog.  It does not redraw the progress bar.           *
  2468. *                                                                             *
  2469. * Parameters: value: the new sub-progress bar maximum value                   *
  2470. *                                                                             *
  2471. * Created by: Greg Ferrar                                                     *
  2472. * Created on: September 4, 1992                                               *
  2473. * Modified:                                                                   *
  2474. \*****************************************************************************/
  2475.  
  2476. void set_sub_progress_bar_max(long value)
  2477. {
  2478.  
  2479.     /* Set the bar to the new value */
  2480.     sub_progress_bar_max = value;
  2481.  
  2482. }    /* set_sub_progress_bar_max() */
  2483.  
  2484.  
  2485.  
  2486. /*****************************************************************************\
  2487. * procedure set_dialog_num                                                    *
  2488. *                                                                             *
  2489. * Purpose: This procedure sets the text of a dialog text item to the value    *
  2490. *           of the passed number.                                             *
  2491. *                                                                             *
  2492. * Parameters: dialog: the dialog to change                                    *
  2493. *             item:   the item number to change                               *
  2494. *             number: the number to change item to                            *
  2495. *                                                                             *
  2496. * Created by: Greg Ferrar                                                     *
  2497. * Created on: September 3, 1992                                               *
  2498. * Modified:                                                                   *
  2499. \*****************************************************************************/
  2500.  
  2501. void set_dialog_num(DialogPtr dialog, short item, long number)
  2502. {
  2503.  
  2504.     Str255    number_string;
  2505.     
  2506.     /* Convert number to a string */
  2507.     NumToString(number, number_string);
  2508.  
  2509.     /* Change the dialog text */
  2510.     set_dialog_text(dialog, item, number_string);
  2511.  
  2512. }    /* set_dialog_num() */
  2513.  
  2514.  
  2515.  
  2516. /*****************************************************************************\
  2517. * procedure set_dialog_real                                                   *
  2518. *                                                                             *
  2519. * Purpose: This procedure sets the text of a dialog text item to the value    *
  2520. *           of the passed real number.                                        *
  2521. *                                                                             *
  2522. * Parameters: dialog: the dialog to change                                    *
  2523. *             item:   the item number to change                               *
  2524. *             number: the real number to change item to                       *
  2525. *                                                                             *
  2526. * Created by: Greg Ferrar                                                     *
  2527. * Created on: September 3, 1992                                               *
  2528. * Modified:                                                                   *
  2529. \*****************************************************************************/
  2530.  
  2531. void set_dialog_real(DialogPtr dialog, short item, real number)
  2532. {
  2533.  
  2534.     Str255    number_string;
  2535.     
  2536.     /* Convert number to a string */
  2537.     sprintf((char *)number_string, "%lg", number);
  2538.  
  2539.     /* Change the dialog text */
  2540.     set_dialog_text(dialog, item, CtoPstr(number_string));
  2541.  
  2542. }    /* set_dialog_real() */
  2543.  
  2544.  
  2545.  
  2546. /*****************************************************************************\
  2547. * procedure set_dialog_text                                                   *
  2548. *                                                                             *
  2549. * Purpose: This procedure sets the text of a dialog text item to the passed   *
  2550. *           string.                                                           *
  2551. *                                                                             *
  2552. * Parameters: dialog: the dialog to change                                    *
  2553. *             item:   the item number to change                               *
  2554. *             string: the string to change item to                            *
  2555. *                                                                             *
  2556. * Created by: Greg Ferrar                                                     *
  2557. * Created on: September 3, 1992                                               *
  2558. * Modified:                                                                   *
  2559. \*****************************************************************************/
  2560.  
  2561. void set_dialog_text(DialogPtr dialog, short item, Str255 string)
  2562. {
  2563.  
  2564.     int        type;
  2565.     Handle    handle;
  2566.     Rect    box;
  2567.  
  2568.     /* Change the dialog text */
  2569.     GetDItem (dialog, item, &type, &handle, &box);
  2570.     SetIText (handle, string);
  2571.  
  2572. }    /* set_dialog_text() */
  2573.  
  2574.  
  2575.  
  2576. /*****************************************************************************\
  2577. * procedure set_dialog_pict                                                   *
  2578. *                                                                             *
  2579. * Purpose: This procedure sets a picture in a dialog box to be the specified  *
  2580. *          PICT resource.                                                     *
  2581. *                                                                             *
  2582. * Parameters: dialog: the dialog to change                                    *
  2583. *             item:   the item number to change                               *
  2584. *             string: the string to change item to                            *
  2585. *                                                                             *
  2586. * Created by: Greg Ferrar                                                     *
  2587. * Created on: September 3, 1992                                               *
  2588. * Modified:                                                                   *
  2589. \*****************************************************************************/
  2590.  
  2591. void set_dialog_pict(DialogPtr dialog, short item, short pic_id)
  2592. {
  2593.  
  2594.     int            type;
  2595.     Handle        handle;
  2596.     PicHandle    pic_handle;
  2597.     Rect        box;
  2598.  
  2599.     /* Read in the picture */
  2600.     pic_handle = GetPicture (pic_id);
  2601.  
  2602.     /* Set the DITL item to be the picture */
  2603.     GetDItem (dialog, item, &type, &handle, &box);
  2604.     SetDItem (dialog, item, type, pic_handle, &box);
  2605.  
  2606. }    /* set_dialog_pict() */
  2607.  
  2608.  
  2609.  
  2610. /*****************************************************************************\
  2611. * procedure dim_focal_distance                                                *
  2612. *                                                                             *
  2613. * Purpose: This procedure is used to dim the focal distance text and edittext *
  2614. *          when appropriate.  The useritem is located directly below the two  *
  2615. *          text items.  When the "Specify Focal Distance" check box is        *
  2616. *          checked, the text items are selected.  When it is not checked, the *
  2617. *          text items are dimmed.                                             *
  2618. *                                                                             *
  2619. * Parameters: all ignored                                                     *
  2620. *                                                                             *
  2621. * Created by: Greg Ferrar                                                     *
  2622. * Created on: August 21, 1992                                                 *
  2623. * Modified:                                                                   *
  2624. \*****************************************************************************/
  2625.  
  2626. pascal void dim_focal_distance (WindowPtr the_window, short item_number)
  2627. {
  2628.  
  2629.     short    item_type;        /* the item type of a DITL item */
  2630.     Handle    item_handle;    /* a handle to a DITL item */
  2631.     Rect    item_box;        /* the bounding box of a DITL item */
  2632.  
  2633.  
  2634.     /* Get the value of the Specify Focal Distance check box; if it is checked,
  2635.         enable the item.  If it is not checked, disable it and grey it out. */
  2636.     if (GetCtlValue (specify_focal_distance_checkbox))    
  2637.         {
  2638.         
  2639.         /* Enable the EditText item */
  2640.         GetDItem (options_dialog, FOCAL_DISTANCE_NUM, &item_type,
  2641.                     &item_handle, &item_box);
  2642.         SetDItem (options_dialog, FOCAL_DISTANCE_NUM,
  2643.                     editText, item_handle, &item_box);
  2644.         
  2645.         /* Draw the frame */
  2646.         InsetRect (&item_box, -3, -3);
  2647.         FrameRect (&item_box);
  2648.         
  2649.         }
  2650.     else        
  2651.         {
  2652.     
  2653.         /* Get the useritem rectangle */
  2654.         GetDItem (options_dialog, DIM_FOCAL_DISTANCE_USERITEM, &item_type,
  2655.                     &item_handle, &item_box);
  2656.                     
  2657.         /* extend it to the right to encompass the text */
  2658.         item_box.right += 200;
  2659.         
  2660.         /* Set the pen mode to Bic, draw over the text in gray */
  2661.         PenMode(patBic);
  2662.         PenPat(gray);
  2663.         PaintRect (&item_box);
  2664.         PenMode(patCopy);
  2665.         
  2666.         /* Disable the EditText item */
  2667.         GetDItem (options_dialog, FOCAL_DISTANCE_NUM, &item_type,
  2668.                     &item_handle, &item_box);
  2669.         SetDItem (options_dialog, FOCAL_DISTANCE_NUM,
  2670.                     (statText | itemDisable), item_handle, &item_box);
  2671.         
  2672.         /* Draw the frame in gray */
  2673.         InsetRect (&item_box, -3, -3);
  2674.         FrameRect (&item_box);
  2675.         PenPat(black);
  2676.         
  2677.         /* Select something else */
  2678.         SelIText (options_dialog, IMAGE_WIDTH_NUM, 0, 32767);
  2679.  
  2680.         }
  2681.  
  2682. }    /* dim_focal_distance() */
  2683.  
  2684.  
  2685.  
  2686.  
  2687.  
  2688. /*****************************************************************************\
  2689. * procedure dim_aliasing_threshold                                            *
  2690. *                                                                             *
  2691. * Purpose: This procedure is used to dim the aliasing threshold text and      *
  2692. *          edittext when appropriate.  The useritem is located directly to    *
  2693. *          the right of the two text items.  When the "Sampling Level" menu   *
  2694. *          is set to 2 or 3, the text items are selected.  When it set to 1,  *
  2695. *          the text items are dimmed.                                         *
  2696. *                                                                             *
  2697. * Parameters: all ignored                                                     *
  2698. *                                                                             *
  2699. * Created by: Greg Ferrar                                                     *
  2700. * Created on: August 21, 1992                                                 *
  2701. * Modified:                                                                   *
  2702. \*****************************************************************************/
  2703.  
  2704. pascal void dim_aliasing_threshold (WindowPtr the_window, short item_number)
  2705. {
  2706.  
  2707.     short    item_type;        /* the item type of a DITL item */
  2708.     Handle    item_handle;    /* a handle to a DITL item */
  2709.     Rect    item_box;        /* the bounding box of a DITL item */
  2710.  
  2711.  
  2712.     /* Get the value of the Sampling Levels menu; if there is sampling,
  2713.         enable the item.  Otherwise, disable it and grey it out. */
  2714.     if (sampling_level_menu_selection != 1)    
  2715.         {
  2716.         
  2717.         /* Enable the EditText item */
  2718.         GetDItem (options_dialog, ALIASING_THRESHOLD_NUM, &item_type,
  2719.                     &item_handle, &item_box);
  2720.         SetDItem (options_dialog, ALIASING_THRESHOLD_NUM,
  2721.                     editText, item_handle, &item_box);
  2722.         
  2723.         /* Draw the frame */
  2724.         InsetRect (&item_box, -3, -3);
  2725.         FrameRect (&item_box);
  2726.         
  2727.         }
  2728.     else        
  2729.         {
  2730.     
  2731.         /* Get the useritem rectangle */
  2732.         GetDItem (options_dialog, DIM_ALIASING_THRESHOLD_USERITEM, &item_type,
  2733.                     &item_handle, &item_box);
  2734.                     
  2735.         /* extend it to the left to encompass the text */
  2736.         item_box.left -= 200;
  2737.         
  2738.         /* Set the pen mode to Bic, draw over the text in gray */
  2739.         PenMode(patBic);
  2740.         PenPat(gray);
  2741.         PaintRect (&item_box);
  2742.         PenMode(patCopy);
  2743.         
  2744.         /* Disable the EditText item */
  2745.         GetDItem (options_dialog, ALIASING_THRESHOLD_NUM, &item_type,
  2746.                     &item_handle, &item_box);
  2747.         SetDItem (options_dialog, ALIASING_THRESHOLD_NUM,
  2748.                     (statText | itemDisable), item_handle, &item_box);
  2749.         
  2750.         /* Draw the frame in gray */
  2751.         InsetRect (&item_box, -3, -3);
  2752.         FrameRect (&item_box);
  2753.         PenPat(black);
  2754.         
  2755.         /* Select something else */
  2756.         SelIText (options_dialog, IMAGE_WIDTH_NUM, 0, 32767);
  2757.  
  2758.         }
  2759.  
  2760. }    /* dim_aliasing_threshold() */
  2761.  
  2762.  
  2763.  
  2764.  
  2765. /*****************************************************************************\
  2766. * procedure dim_relinquish_control                                            *
  2767. *                                                                             *
  2768. * Purpose: This procedure is used to dim the relinquish control text and      *
  2769. *          edittext.  The useritem is located directly to the right of the    *
  2770. *          text items.  When the "Allow Background Tasks" check box is        *
  2771. *          checked, the text items are selected.  When it is not checked, the *
  2772. *          text items are dimmed.                                             *
  2773. *                                                                             *
  2774. * Parameters: all ignored                                                     *
  2775. *                                                                             *
  2776. * Created by: Greg Ferrar                                                     *
  2777. * Created on: August 21, 1992                                                 *
  2778. * Modified:                                                                   *
  2779. \*****************************************************************************/
  2780.  
  2781. pascal void dim_relinquish_control (WindowPtr the_window, short item_number)
  2782. {
  2783.  
  2784.     short    item_type;        /* the item type of a DITL item */
  2785.     Handle    item_handle;    /* a handle to a DITL item */
  2786.     Rect    item_box;        /* the bounding box of a DITL item */
  2787.  
  2788.  
  2789.     /* Get the value of the Allow Background Tasks check box; if it is checked,
  2790.         enable the item.  If it is not checked, disable it and grey it out. */
  2791.     if (GetCtlValue (allow_background_tasks_checkbox))    
  2792.         {
  2793.         
  2794.         /* Enable the EditText item */
  2795.         GetDItem (preferences_dialog, ALLOW_BACKGROUND_TASKS_NUM, &item_type,
  2796.                     &item_handle, &item_box);
  2797.         SetDItem (preferences_dialog, ALLOW_BACKGROUND_TASKS_NUM,
  2798.                     editText, item_handle, &item_box);
  2799.         
  2800.         /* Draw the frame */
  2801.         InsetRect (&item_box, -3, -3);
  2802.         FrameRect (&item_box);
  2803.         
  2804.         /* Select the editText */
  2805.         SelIText (preferences_dialog, ALLOW_BACKGROUND_TASKS_NUM, 0, 32767);
  2806.  
  2807.         }
  2808.     else        
  2809.         {
  2810.     
  2811.         /* Select something else */
  2812.         SelIText (preferences_dialog, DUMMY_EDITTEXT, 0, 32767);
  2813.  
  2814.         /* Get the useritem rectangle */
  2815.         GetDItem (preferences_dialog, DIM_ALLOW_BACKGROUND_TASKS_USERITEM, &item_type,
  2816.                     &item_handle, &item_box);
  2817.                     
  2818.         /* extend it to the left to encompass the text */
  2819.         item_box.left -= 300;
  2820.         
  2821.         /* Set the pen mode to Bic, draw over the text in gray */
  2822.         PenMode(patBic);
  2823.         PenPat(gray);
  2824.         PaintRect (&item_box);
  2825.         PenMode(patCopy);
  2826.         
  2827.         /* Disable the EditText item */
  2828.         GetDItem (preferences_dialog, ALLOW_BACKGROUND_TASKS_NUM, &item_type,
  2829.                     &item_handle, &item_box);
  2830.         SetDItem (preferences_dialog, ALLOW_BACKGROUND_TASKS_NUM,
  2831.                     (statText | itemDisable), item_handle, &item_box);
  2832.         
  2833.         /* Draw the frame in gray */
  2834.         InsetRect (&item_box, -3, -3);
  2835.         FrameRect (&item_box);
  2836.         PenPat(black);
  2837.  
  2838.         }
  2839.  
  2840. }    /* dim_relinquish_control() */
  2841.  
  2842.  
  2843.  
  2844. /*****************************************************************************\
  2845. * procedure dim_show_image_rendering                                          *
  2846. *                                                                             *
  2847. * Purpose: This procedure is used to dim the Show Image Rendering option when *
  2848. *          Color QuickDraw is not available.                                  *
  2849. *                                                                             *
  2850. * Parameters: all ignored                                                     *
  2851. *                                                                             *
  2852. * Created by: Greg Ferrar                                                     *
  2853. * Created on: September 10, 1992                                              *
  2854. * Modified:                                                                   *
  2855. \*****************************************************************************/
  2856.  
  2857. pascal void dim_show_image_rendering (WindowPtr the_window, short item_number)
  2858. {
  2859.  
  2860.     short    item_type;        /* the item type of a DITL item */
  2861.     Handle    item_handle;    /* a handle to a DITL item */
  2862.     Rect    item_box;        /* the bounding box of a DITL item */
  2863.  
  2864.  
  2865.     /* If Color QuickDraw is not available, dim the Show Image Rendering checkbox */
  2866.     if (!f8bit_QD_available)
  2867.         {
  2868.                 
  2869.         /* Get the useritem rectangle */
  2870.         GetDItem (preferences_dialog, DIM_SHOW_IMAGE_RENDERING_USERITEM, &item_type,
  2871.                     &item_handle, &item_box);
  2872.  
  2873.         /* extend it to the left to encompass the checkbox */
  2874.         item_box.left -= 300;
  2875.  
  2876.         /* Set the pen mode to Bic, draw over the check boxes in gray */
  2877.         PenMode(patBic);
  2878.         PenPat(gray);
  2879.         PaintRect (&item_box);
  2880.         PenPat(black);
  2881.         PenMode(patCopy);
  2882.         
  2883.         /* Disable the checkbox */
  2884.         HiliteControl(show_image_rendering_checkbox, 255);
  2885.         SetCtlValue(show_image_rendering_checkbox, FALSE);
  2886.         
  2887.         }
  2888.  
  2889. }    /* dim_show_image_rendering() */
  2890.  
  2891.  
  2892.  
  2893. /*****************************************************************************\
  2894. * procedure dim_keep_image_in_memory                                          *
  2895. *                                                                             *
  2896. * Purpose: This procedure is used to dim the Keep Image In Memory option when *
  2897. *          32-bit QuickDraw is not available.                                 *
  2898. *                                                                             *
  2899. * Parameters: all ignored                                                     *
  2900. *                                                                             *
  2901. * Created by: Greg Ferrar                                                     *
  2902. * Created on: September 10, 1992                                              *
  2903. * Modified:                                                                   *
  2904. \*****************************************************************************/
  2905.  
  2906. pascal void dim_keep_image_in_memory (WindowPtr the_window, short item_number)
  2907. {
  2908.  
  2909.     short    item_type;        /* the item type of a DITL item */
  2910.     Handle    item_handle;    /* a handle to a DITL item */
  2911.     Rect    item_box;        /* the bounding box of a DITL item */
  2912.  
  2913.  
  2914.     /* If 32-bit QuickDraw is not available, dim the Keep Image In Memory checkbox */
  2915.     if (!f32bit_QD_available)
  2916.         {
  2917.                 
  2918.         /* Get the useritem rectangle */
  2919.         GetDItem (preferences_dialog, DIM_KEEP_IMAGE_IN_MEMORY_USERITEM, &item_type,
  2920.                     &item_handle, &item_box);
  2921.  
  2922.         /* extend it to the left to encompass the checkbox */
  2923.         item_box.left -= 300;
  2924.  
  2925.         /* Set the pen mode to Bic, draw over the check boxes in gray */
  2926.         PenMode(patBic);
  2927.         PenPat(gray);
  2928.         PaintRect (&item_box);
  2929.         PenPat(black);
  2930.         PenMode(patCopy);
  2931.         
  2932.         /* Disable the checkbox */
  2933.         HiliteControl(keep_image_in_memory_checkbox, 255);
  2934.         SetCtlValue(keep_image_in_memory_checkbox, FALSE);
  2935.         
  2936.         }
  2937.  
  2938. }    /* dim_keep_image_in_memory() */
  2939.  
  2940.  
  2941.  
  2942. /*****************************************************************************\
  2943. * procedure dim_stereo_separation                                             *
  2944. *                                                                             *
  2945. * Purpose: This procedure is used to dim the stereo separation items          *
  2946. *          when appropriate.  The useritem is located directly to the right   *
  2947. *          of the items.  When the View mode is "right eye" or "left eye,"    *
  2948. *          the text items are selected.  When it is "normal," the items are   *
  2949. *          dimmed.                                                            *
  2950. *                                                                             *
  2951. * Parameters: all ignored                                                     *
  2952. *                                                                             *
  2953. * Created by: Greg Ferrar                                                     *
  2954. * Created on: August 21, 1992                                                 *
  2955. * Modified:                                                                   *
  2956. \*****************************************************************************/
  2957.  
  2958. pascal void dim_stereo_separation (WindowPtr the_window, short item_number)
  2959. {
  2960.  
  2961.     short    item_type;        /* the item type of a DITL item */
  2962.     Handle    item_handle;    /* a handle to a DITL item */
  2963.     Rect    item_box;        /* the bounding box of a DITL item */
  2964.     Rect    edittext_box;
  2965.     char    num_text[100];    /* temporary text storage */
  2966.  
  2967.  
  2968.     /* If the view mode is normal, disable the stereo separation items.
  2969.         Otherwise, enable them. */
  2970.     if (view_menu_selection != 1)    
  2971.         {
  2972.         
  2973.         /* Enable the EditText item */
  2974.         GetDItem (options_dialog, STEREO_SEPARATION_NUM, &item_type,
  2975.                     &item_handle, &item_box);
  2976.         SetDItem (options_dialog, STEREO_SEPARATION_NUM,
  2977.                     editText, item_handle, &item_box);
  2978.         
  2979.         /* If the text is 0.0 or 0, set it to 1.0 (it's not legal to have no
  2980.             separation in stereoscopic mode) */
  2981.         GetIText (item_handle, num_text);
  2982.         if ( (!strcmp(PtoCstr(num_text), "0")) || (!strcmp(PtoCstr(num_text), "0.0")) )
  2983.             SetIText (item_handle, "\p1.0");
  2984.     
  2985.         /* Draw the frame */
  2986.         InsetRect (&item_box, -3, -3);
  2987.         FrameRect (&item_box);
  2988.         
  2989.         /* Enable the stereo separation menu */
  2990.         GetDItem (options_dialog, STEREO_SEPARATION_POPUP, &item_type,
  2991.                     &item_handle, &item_box);
  2992.         SetDItem (options_dialog, STEREO_SEPARATION_POPUP,
  2993.                     userItem, item_handle, &item_box);
  2994.         
  2995.         }
  2996.     else        
  2997.         {
  2998.     
  2999.         /* Disable the EditText item */
  3000.         GetDItem (options_dialog, STEREO_SEPARATION_NUM, &item_type,
  3001.                     &item_handle, &edittext_box);
  3002.         SetDItem (options_dialog, STEREO_SEPARATION_NUM,
  3003.                     (statText | itemDisable), item_handle, &edittext_box);
  3004.         
  3005.         /* If the text isn't 0.0 or 0, set it to 0 (it's not legal to have
  3006.             stereo separation in monoscopic mode) */
  3007.         GetIText (item_handle, num_text);
  3008.         if ( (strcmp(PtoCstr(num_text), "0")) && (strcmp(PtoCstr(num_text), "0.0")) )
  3009.             SetIText (item_handle, "\p0.0");
  3010.     
  3011.         /* Disable the stereo separation menu */
  3012.         GetDItem (options_dialog, STEREO_SEPARATION_POPUP, &item_type,
  3013.                     &item_handle, &item_box);
  3014.         SetDItem (options_dialog, STEREO_SEPARATION_POPUP,
  3015.                     userItem + itemDisable, item_handle, &item_box);
  3016.         
  3017.         /* Get the useritem rectangle */
  3018.         GetDItem (options_dialog, DIM_STEREO_SEPARATION_USERITEM, &item_type,
  3019.                     &item_handle, &item_box);
  3020.                     
  3021.         /* extend it to the right to encompass the text */
  3022.         item_box.right += 350;
  3023.         
  3024.         /* Set the pen mode to Bic, draw over the text in gray */
  3025.         PenMode(patBic);
  3026.         PenPat(gray);
  3027.         PaintRect (&item_box);
  3028.         PenMode(patCopy);
  3029.         
  3030.         /* Draw the frame in gray */
  3031.         InsetRect (&edittext_box, -3, -3);
  3032.         FrameRect (&edittext_box);
  3033.         PenPat(black);
  3034.         
  3035.         }
  3036.  
  3037. }    /* dim_stereo_separation() */
  3038.  
  3039.  
  3040.  
  3041. /*****************************************************************************\
  3042. * procedure draw_popup_menu                                                   *
  3043. *                                                                             *
  3044. * Purpose: This procedure draws a popup menu in the_box, with the_string as   *
  3045. *          the current menu text.  It also draws the down arrow at the right. *
  3046. *          If enabled is false, it is drawn grayed out.                       *
  3047. *                                                                             *
  3048. * Parameters: the_box:    the bounding box of the popup menu                  *
  3049. *             the_string: the text of the current selection (pascal string)   *
  3050. *             enabled:    TRUE if this menu is enabled, FALSE if grayed.      *
  3051. *                                                                             *
  3052. * Created by: Greg Ferrar                                                     *
  3053. * Created on: August 21, 1992                                                 *
  3054. * Modified:                                                                   *
  3055. \*****************************************************************************/
  3056.  
  3057. void draw_popup (Rect *the_box, Str255 the_string, short enabled)
  3058. {
  3059.     Rect down_arrow_rect = {0, 0, 6, 12};
  3060.     Point pen_pos;
  3061.     Pattern *draw_pat = (enabled) ? &black : &gray;
  3062.     
  3063.     /* make room for the outline */
  3064.     
  3065.     the_box->right--;
  3066.     the_box->bottom--;
  3067.     
  3068.     /* Outline rectangle and add drop box */
  3069.     PenPat (draw_pat);
  3070.     OffsetRect (the_box, 1, 1);
  3071.     FrameRect (the_box);
  3072.     OffsetRect (the_box, -1, -1);
  3073.     PenPat (white);
  3074.     PaintRect (the_box);
  3075.     PenPat (draw_pat);
  3076.     FrameRect (the_box);
  3077.  
  3078.     /* Draw the text in the rectangle */
  3079.     MoveTo (the_box->left+15, the_box->bottom-6);
  3080.     DrawString (the_string);
  3081.  
  3082.     /* Draw the down arrow at the right of the box */
  3083.     OffsetRect (&down_arrow_rect, the_box->right-17, the_box->bottom-13);
  3084.     if (enabled)
  3085.         DrawPicture(down_arrow_picture, &down_arrow_rect);
  3086.     else
  3087.         DrawPicture(down_arrow_picture_grayed, &down_arrow_rect);
  3088.  
  3089.     PenPat (black);
  3090.     
  3091. }    /* draw_popup() */
  3092.  
  3093.  
  3094.  
  3095. /*****************************************************************************\
  3096. * procedure install_popup_menu_hook                                           *
  3097. *                                                                             *
  3098. * Purpose: This procedure installs a hook into the menu defproc of the popup  *
  3099. *          menu in order to force the width of the menu to allow for the      *
  3100. *          standard down arrow within the popup.                              *
  3101. *                                                                             *
  3102. * Parameters: popup_menu:      the menu itself                                *
  3103. *             menu_id:         the resource ID of the menu                    *
  3104. *             popup_text_id:   the ID of the text item in the options dialog  *
  3105. *                              which should be inverted while the menu is     *
  3106. *                              popped up.  (0 if nothing should be inverted)  *
  3107. *             menu_upper_left: the upper left corner of the popup box, in     *
  3108. *                              global coordinates.                            *
  3109. *             menu_selection:  the current selection in the menu              *
  3110. *                                                                             *
  3111. * Created by: Greg Ferrar                                                     *
  3112. * Created on: August 21, 1992                                                 *
  3113. * Modified:                                                                   *
  3114. \*****************************************************************************/
  3115.  
  3116.     typedef struct tMenuHook    /* The structure of the menu hook routine */
  3117.     {
  3118.         short    jmp;
  3119.         long    addr;
  3120.         Handle    realMenuProc;
  3121.         
  3122.     } tMenuHook, **tMenuHookHndl;
  3123.     
  3124. void install_popup_menu_hook(MenuHandle popup_menu)
  3125. {
  3126.  
  3127.     tMenuHookHndl    theHook = (tMenuHookHndl) NewHandle ( sizeof( tMenuHook));
  3128.     
  3129.     /* install a hook which just jumps to MenuProc */
  3130.     (**theHook).jmp = 0x4EF9;        /* JMP instruction */
  3131.     (**theHook).addr = (long) MenuProc;
  3132.     (**theHook).realMenuProc = (**popup_menu).menuProc;    
  3133.     
  3134.     (**popup_menu).menuProc = (Handle) theHook;
  3135.     
  3136.     FlushCache();    /* After modifying code, we must flush the cache on 68040s */
  3137.  
  3138. }    /* install_popup_menu_hook() */
  3139.  
  3140.  
  3141. /******************************************************************************
  3142.  FlushCache        TCL 1.1.1 DLP 9/27/91
  3143.  
  3144.      Flush the CPU cache(s). This is required on the 68040 after modifying
  3145.      code. 
  3146.  ******************************************************************************/
  3147.  
  3148. #define _CacheFlushTrap        0xA0BD
  3149.  
  3150. void FlushCache(void)
  3151. {
  3152.     if (TrapAvailable( _CacheFlushTrap))
  3153.         asm
  3154.         {
  3155.             dc.w _CacheFlushTrap
  3156.         }
  3157. }
  3158.  
  3159.  
  3160. /******************************************************************************
  3161.  TrapAvailable
  3162.  
  3163.      Check whether a certain trap exists on this machine. This function uses
  3164.      the new method as per IM VI, p. 3-8.
  3165.      
  3166.  ******************************************************************************/
  3167.  
  3168. #define _InitGraf                        0xA86E
  3169. #define _Unimplemented                    0xA89F
  3170.  
  3171. Boolean TrapAvailable( short theTrap)
  3172. {
  3173.     TrapType tType;
  3174.     short    numToolBoxTraps;
  3175.     
  3176.                 // first determine the trap type
  3177.                 
  3178.     tType = (theTrap & 0x800) > 0 ? ToolTrap : OSTrap;
  3179.     
  3180.                 // next find out how many traps there are
  3181.                 
  3182.     if (NGetTrapAddress( _InitGraf, ToolTrap) == NGetTrapAddress( 0xAA6E, ToolTrap))
  3183.         numToolBoxTraps = 0x200;
  3184.     else
  3185.         numToolBoxTraps = 0x400;
  3186.     
  3187.                 // check if the trap number is too big for the
  3188.                 // current trap table
  3189.                 
  3190.     if (tType == ToolTrap)
  3191.     {
  3192.         theTrap &= 0x7FF;
  3193.         if (theTrap >= numToolBoxTraps)
  3194.             theTrap = _Unimplemented;
  3195.     }
  3196.     
  3197.                 // the trap is implemented if its address is
  3198.                 // different from the unimplemented trap
  3199.                 
  3200.     return (NGetTrapAddress( theTrap, tType) != 
  3201.             NGetTrapAddress(_Unimplemented, ToolTrap));
  3202. }
  3203.  
  3204.  
  3205. /* This is the custom menu defproc that is called by the Menu Manager    */
  3206. /* All it does is call the original defproc and then check if the        */
  3207. /* message was mSizeMsg. If it was, it patches the menuWidth to allow    */
  3208. /* room for the down arrow                                                */
  3209.  
  3210. static pascal void MenuProc( short message, MenuHandle menu, Rect *menuRect,
  3211.                     Point hitPt, short *whichItem)
  3212. {
  3213.     tMenuHookHndl    menuHook;
  3214.     Handle             realMenuProc;
  3215.     SignedByte        state;
  3216.     
  3217.     /* get handle to the real menu proc */                    
  3218.     menuHook = (tMenuHookHndl) (**menu).menuProc;
  3219.     realMenuProc = (**menuHook).realMenuProc;
  3220.  
  3221.     /* Load the real menu proc into memory, and call it */
  3222.     LoadResource( realMenuProc);
  3223.     state = HGetState( realMenuProc);
  3224.     HLock( realMenuProc);
  3225.     CallPascal( message, menu, menuRect, hitPt, whichItem, *realMenuProc);
  3226.     HSetState( realMenuProc, state);
  3227.  
  3228.     /* If it is a mSizeMsg, change the size */    
  3229.     if (message == mSizeMsg)
  3230.         (**menu).menuWidth += 14;
  3231.  
  3232. }    /* MenuProc() */
  3233.  
  3234.  
  3235.  
  3236. /*****************************************************************************\
  3237. * procedure handle_checkbox_click                                             *
  3238. *                                                                             *
  3239. * Purpose: This procedure handles a click in a check box in the a             *
  3240. *          dialog box.  It toggles the value of the check box.  If it is the  *
  3241. *          "Specify Focal Distance" check box, it also updates.               *
  3242. *                                                                             *
  3243. * Parameters: check_box:      the check box itself                            *
  3244. *                                                                             *
  3245. * Created by: Greg Ferrar                                                     *
  3246. * Created on: August 22, 1992                                                 *
  3247. * Modified:                                                                   *
  3248. \*****************************************************************************/
  3249.  
  3250. void handle_checkbox_click(ControlHandle check_box)
  3251. {
  3252.  
  3253.     short    type;            /* the item type of a DITL item */
  3254.     Handle    handle;            /* a handle to a DITL item */
  3255.     Rect    rect;            /* the bounding box of a DITL item */
  3256.     short    current_value;    /* the current value of the checkbox */
  3257.  
  3258.     /* Get current value of the checkbox */
  3259.     current_value = GetCtlValue (check_box);
  3260.  
  3261.     /* Set the value to the opposite */
  3262.     SetCtlValue (check_box, !current_value);
  3263.  
  3264.     /* If this is the "Animate" checkbox, show or hide the Animation dialog */
  3265.     if (check_box == animate_checkbox)
  3266.         {
  3267.         
  3268.         /* Set the Save... text appropriately */
  3269.         SetItem(file_menu, SAVE_ITEM, (current_value) ? "\pSave Image…" : "\pSave Animation…");
  3270.         
  3271.         /* If the user clicked it on, show the Animation dialog.  Otherwise,
  3272.             hide the dialog. */
  3273.         if (!current_value)
  3274.             show_animation_dialog(TRUE);
  3275.         else
  3276.             hide_animation_dialog();
  3277.         }
  3278.  
  3279.     /* If this is the "Specify Focal Distance" check box, set things up so that
  3280.         the "Focal Distance" text and the dimming useritem get refreshed. */
  3281.     else if (check_box == specify_focal_distance_checkbox)
  3282.         {
  3283.         
  3284.         /* Select something else */
  3285.         SelIText (options_dialog, IMAGE_WIDTH_NUM, 0, 32767);
  3286.         
  3287.         /* Get the rectangle of the useritem (just beneath the text in the DITL */
  3288.         GetDItem (options_dialog, DIM_FOCAL_DISTANCE_USERITEM, &type,
  3289.                     &handle, &rect); 
  3290.                     
  3291.         /* extend the rectangle to the right so it encloses the text */
  3292.         rect.right += 200;
  3293.         
  3294.         /* make the whole area invalid to it gets updated later */
  3295.         SetPort (options_dialog);
  3296.         InvalRect (&rect);
  3297.         }
  3298.         
  3299.     /* If this is the "Allow Background Tasks" check box, set things up so that
  3300.         the relinquish control text and the dimming useritem get refreshed. */
  3301.     else if (check_box == allow_background_tasks_checkbox)
  3302.         {
  3303.         
  3304.         /* Get the rectangle of the useritem (just to the right of the text
  3305.             in the DITL) */
  3306.         GetDItem (preferences_dialog, DIM_ALLOW_BACKGROUND_TASKS_USERITEM, &type,
  3307.                     &handle, &rect); 
  3308.                     
  3309.         /* extend the rectangle to the right so it encloses the text */
  3310.         rect.left -= 300;
  3311.         
  3312.         /* make the whole area invalid to it gets updated later */
  3313.         SetPort (preferences_dialog);
  3314.         InvalRect (&rect);
  3315.         }
  3316.         
  3317. }    /* handle_checkbox_click() */
  3318.  
  3319.  
  3320.  
  3321. /*****************************************************************************\
  3322. * procedure handle_popup_click                                                *
  3323. *                                                                             *
  3324. * Purpose: This procedure handles a click in a popup menu in the any          *
  3325. *          dialog box.  It pops up the menu and saves the new selection.      *
  3326. *                                                                             *
  3327. * Parameters: popup_menu:      the menu itself                                *
  3328. *             menu_id:         the resource ID of the menu                    *
  3329. *             popup_text_id:   the ID of the text item in the options dialog  *
  3330. *                              which should be inverted while the menu is     *
  3331. *                              popped up.  (0 if nothing should be inverted)  *
  3332. *             menu_upper_left: the upper left corner of the popup box, in     *
  3333. *                              global coordinates.                            *
  3334. *             menu_selection:  the current selection in the menu              *
  3335. *                                                                             *
  3336. * Created by: Greg Ferrar                                                     *
  3337. * Created on: August 21, 1992                                                 *
  3338. * Modified:                                                                   *
  3339. \*****************************************************************************/
  3340.  
  3341. void handle_popup_click(DialogPtr the_dialog, MenuHandle popup_menu, short menu_id,
  3342.                         short popup_text_id, short popup_useritem_id,
  3343.                         Point menu_upper_left, short *menu_selection)
  3344. {
  3345.     Rect        item_rect, invert_rect;
  3346.     Handle        item_handle;
  3347.     int         item_type;
  3348.     long        result;
  3349.     short        new_selection;
  3350.     
  3351.     /* Make sure we draw in the dialog box */
  3352.     SetPort (the_dialog);
  3353.  
  3354.     /* Invert the popup text, if any */
  3355.     if (popup_text_id)
  3356.         {
  3357.         /* Find the rectangle of the text item to invert */
  3358.         GetDItem (the_dialog, popup_text_id, &item_type, &item_handle,
  3359.                     &invert_rect); 
  3360.         InvertRect (&invert_rect);
  3361.         }
  3362.  
  3363.     /* Pop up the menu */
  3364.     InsertMenu (popup_menu, -1);
  3365.     result = PopUpMenuSelect (popup_menu, menu_upper_left.v, menu_upper_left.h,
  3366.                                 *menu_selection);
  3367.     DeleteMenu (menu_id);
  3368.  
  3369.     /* find the new selection, if any */
  3370.     new_selection = LoWord (result);
  3371.  
  3372.     /* If there was a selection, and it is different from the old one, update
  3373.         the menu. */
  3374.     if (result && (new_selection != *menu_selection))
  3375.         {
  3376.     
  3377.         /* Uncheck the old selection, and check the new */
  3378.         CheckItem (popup_menu, *menu_selection, FALSE);
  3379.         CheckItem (popup_menu, new_selection, TRUE);
  3380.     
  3381.         /* If this is the View popup, and there was a switch from monoscopic to
  3382.             stereoscopic or back, refresh the Stereo separation items. */
  3383.         if ((menu_id == VIEW_MENU) && ((*menu_selection == 1) || (new_selection == 1)))
  3384.             {
  3385.             
  3386.             /* Get the rectangle of the useritem (just to the right of the items */
  3387.             GetDItem (options_dialog, DIM_STEREO_SEPARATION_USERITEM, &item_type,
  3388.                         &item_handle, &item_rect); 
  3389.                         
  3390.             /* extend the rectangle rightward so it encloses the text */
  3391.             item_rect.right += 350;
  3392.             
  3393.             /* make the whole area invalid to it gets updated later */
  3394.             SetPort (options_dialog);
  3395.             InvalRect (&item_rect);
  3396.             
  3397.             }
  3398.  
  3399.         /* If this is the Sampling Level popup, and there was a switch Level 0
  3400.             to level 1, 2 or 3, or from 1, 2 or 3 to 0, refresh the Aliasing
  3401.             Threshold items. */
  3402.         if ((menu_id == SAMPLING_LEVEL_MENU) &&
  3403.                             ((*menu_selection == 1) || (new_selection == 1)))
  3404.             {
  3405.             
  3406.             /* Get the rectangle of the useritem (just to the right of the items */
  3407.             GetDItem (options_dialog, DIM_ALIASING_THRESHOLD_USERITEM, &item_type,
  3408.                         &item_handle, &item_rect); 
  3409.                         
  3410.             /* extend the rectangle leftward so it encloses the text */
  3411.             item_rect.left -= 200;
  3412.             
  3413.             /* make the whole area invalid to it gets updated later */
  3414.             SetPort (options_dialog);
  3415.             InvalRect (&item_rect);
  3416.             
  3417.             }
  3418.             
  3419.         /* If this is the Textures popup, set the texture_mode_changed flag,
  3420.             and update the Render Button */
  3421.         if (menu_id == TEXTURE_MENU)
  3422.             {
  3423.             
  3424.             /* set the texture_mode_changed depending on whether the selected
  3425.                 texture mode is different from last render */
  3426.             texture_mode_changed = (new_selection != (last_texture_selection + 1));
  3427.             
  3428.             /* Update the "Render" button */
  3429.             update_render_button();
  3430.  
  3431.             }
  3432.  
  3433.         /* Save the new selection */
  3434.         *menu_selection = new_selection;
  3435.     
  3436.         /* Update the popup menu */
  3437.             draw_any_popup (the_dialog, popup_useritem_id, popup_menu,
  3438.                             *menu_selection, &menu_upper_left);        
  3439.         }    
  3440.     
  3441.     /* Invert the popup text, if any */
  3442.     if (popup_text_id)
  3443.         InvertRect (&invert_rect);
  3444.  
  3445.  
  3446. }    /* handle_popup_click() */
  3447.  
  3448.  
  3449.  
  3450. /*****************************************************************************\
  3451. * procedure update_render_button                                              *
  3452. *                                                                             *
  3453. * Purpose: This procedure updates the title of the Render button.  The button *
  3454. *          is called Render Again if the scene from last render is still in   *
  3455. *          memory, and the same file is being rendered, and the texture mode  *
  3456. *          has not changed.                                                   *
  3457. *                                                                             *
  3458. * Created by: Greg Ferrar                                                     *
  3459. * Created on: September 1, 1992                                               *
  3460. * Modified:                                                                   *
  3461. \*****************************************************************************/
  3462.  
  3463. void update_render_button(void)
  3464. {
  3465.  
  3466.     if ((scene_in_memory) && (rendering_same_file) && (!texture_mode_changed))
  3467.         SetCTitle(render_button_handle, "\pRender Again");
  3468.     
  3469.     else
  3470.         SetCTitle(render_button_handle, "\pRender");
  3471.  
  3472. }    /* update_render_button() */
  3473.  
  3474.  
  3475.  
  3476. /*****************************************************************************\
  3477. * procedure draw_any_popup                                                    *
  3478. *                                                                             *
  3479. * Purpose: This procedure draws any of the popup menus in a dialog box.       *
  3480. *                                                                             *
  3481. * Parameters: item_number:    the ID of the user item                         *
  3482. *             menu:           the menu                                        *
  3483. *             menu_selection: the current selection in the menu               *
  3484. *             upper_left:     the upper left corner of the popup box          *
  3485. *                                                                             *
  3486. * Created by: Greg Ferrar                                                     *
  3487. * Created on: August 21, 1992                                                 *
  3488. * Modified:                                                                   *
  3489. \*****************************************************************************/
  3490.  
  3491. void draw_any_popup (DialogPtr the_dialog, short item_number, MenuHandle menu,
  3492.                             short menu_selection, Point *upper_left)
  3493. {
  3494.     Rect        item_rect;
  3495.     Handle        item_handle;
  3496.     int         item_type;
  3497.     Str255        the_string;
  3498.  
  3499.     SetPort(the_dialog);
  3500.  
  3501.     /* Find the surrounding rectangle */
  3502.     GetDItem (the_dialog, item_number, &item_type, &item_handle,
  3503.                 &item_rect); 
  3504.  
  3505.     /* the currently selected item in the popup */
  3506.     GetItem(menu, menu_selection, the_string);
  3507.     
  3508.     /* Draw the popup */
  3509.     draw_popup (&item_rect, the_string, TRUE);
  3510.  
  3511.     /* Find the upper left corner so we can pop it up later */
  3512.     upper_left->h = item_rect.left + 1;
  3513.     upper_left->v = item_rect.top + 1;
  3514.     LocalToGlobal (upper_left);
  3515.  
  3516. }    /* draw_any_popup() */
  3517.  
  3518.  
  3519.  
  3520. /*****************************************************************************\
  3521. * procedure draw_antialiasing_popup                                           *
  3522. *                                                                             *
  3523. * Purpose: This procedure draws the antialiasing popup menu in the options    *
  3524. *          dialog box.                                                        *
  3525. *                                                                             *
  3526. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3527. *             the_window: ignored.                                            *
  3528. *                                                                             *
  3529. * Created by: Greg Ferrar                                                     *
  3530. * Created on: August 21, 1992                                                 *
  3531. * Modified:                                                                   *
  3532. \*****************************************************************************/
  3533.  
  3534. pascal void draw_antialiasing_popup (WindowPtr the_window, short item_number)
  3535. {
  3536.  
  3537.     /* Draw the popup */
  3538.     draw_any_popup (options_dialog, item_number, antialiasing_menu,
  3539.                     antialiasing_menu_selection, &antialiasing_menu_upper_left);
  3540.  
  3541. }    /* draw_antialiasing_popup() */
  3542.  
  3543.  
  3544.  
  3545. /*****************************************************************************\
  3546. * procedure draw_lighting_popup                                               *
  3547. *                                                                             *
  3548. * Purpose: This procedure draws the lighting popup menu in the options        *
  3549. *          dialog box.                                                        *
  3550. *                                                                             *
  3551. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3552. *             the_window: ignored.                                            *
  3553. *                                                                             *
  3554. * Created by: Greg Ferrar                                                     *
  3555. * Created on: August 21, 1992                                                 *
  3556. * Modified:                                                                   *
  3557. \*****************************************************************************/
  3558.  
  3559. pascal void draw_lighting_popup (WindowPtr the_window, short item_number)
  3560. {
  3561.  
  3562.     /* Draw the popup */
  3563.     draw_any_popup (options_dialog, item_number, lighting_menu,
  3564.                     lighting_menu_selection, &lighting_menu_upper_left);
  3565.  
  3566. }    /* draw_lighting_popup() */
  3567.  
  3568.  
  3569.  
  3570. /*****************************************************************************\
  3571. * procedure draw_normal_popup                                                 *
  3572. *                                                                             *
  3573. * Purpose: This procedure draws the normal popup menu in the options          *
  3574. *          dialog box.                                                        *
  3575. *                                                                             *
  3576. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3577. *             the_window: ignored.                                            *
  3578. *                                                                             *
  3579. * Created by: Greg Ferrar                                                     *
  3580. * Created on: August 21, 1992                                                 *
  3581. * Modified:                                                                   *
  3582. \*****************************************************************************/
  3583.  
  3584. pascal void draw_normal_popup (WindowPtr the_window, short item_number)
  3585. {
  3586.  
  3587.     /* Draw the popup */
  3588.     draw_any_popup (options_dialog, item_number, normal_menu,
  3589.                     normal_menu_selection, &normal_menu_upper_left);
  3590.  
  3591. }    /* draw_normal_popup() */
  3592.  
  3593.  
  3594.  
  3595. /*****************************************************************************\
  3596. * procedure draw_intersect_popup                                              *
  3597. *                                                                             *
  3598. * Purpose: This procedure draws the intersect popup menu in the options       *
  3599. *          dialog box.                                                        *
  3600. *                                                                             *
  3601. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3602. *             the_window: ignored.                                            *
  3603. *                                                                             *
  3604. * Created by: Greg Ferrar                                                     *
  3605. * Created on: August 21, 1992                                                 *
  3606. * Modified:                                                                   *
  3607. \*****************************************************************************/
  3608.  
  3609. pascal void draw_intersect_popup (WindowPtr the_window, short item_number)
  3610. {
  3611.  
  3612.     /* Draw the popup */
  3613.     draw_any_popup (options_dialog, item_number, intersect_menu,
  3614.                     intersect_menu_selection, &intersect_menu_upper_left);
  3615.  
  3616. }    /* draw_intersect_popup() */
  3617.  
  3618.  
  3619.  
  3620. /*****************************************************************************\
  3621. * procedure draw_texture_popup                                                *
  3622. *                                                                             *
  3623. * Purpose: This procedure draws the texture popup menu in the options         *
  3624. *          dialog box.                                                        *
  3625. *                                                                             *
  3626. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3627. *             the_window: ignored.                                            *
  3628. *                                                                             *
  3629. * Created by: Greg Ferrar                                                     *
  3630. * Created on: August 21, 1992                                                 *
  3631. * Modified:                                                                   *
  3632. \*****************************************************************************/
  3633.  
  3634. pascal void draw_texture_popup (WindowPtr the_window, short item_number)
  3635. {
  3636.  
  3637.     /* Draw the popup */
  3638.     draw_any_popup (options_dialog, item_number, texture_menu,
  3639.                     texture_menu_selection, &texture_menu_upper_left);
  3640.  
  3641. }    /* draw_texture_popup() */
  3642.  
  3643.  
  3644.  
  3645. /*****************************************************************************\
  3646. * procedure draw_shading_popup                                                *
  3647. *                                                                             *
  3648. * Purpose: This procedure draws the shading popup menu in the options         *
  3649. *          dialog box.                                                        *
  3650. *                                                                             *
  3651. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3652. *             the_window: ignored.                                            *
  3653. *                                                                             *
  3654. * Created by: Greg Ferrar                                                     *
  3655. * Created on: August 21, 1992                                                 *
  3656. * Modified:                                                                   *
  3657. \*****************************************************************************/
  3658.  
  3659. pascal void draw_shading_popup (WindowPtr the_window, short item_number)
  3660. {
  3661.  
  3662.     /* Draw the popup */
  3663.     draw_any_popup (options_dialog, item_number, shading_menu,
  3664.                     shading_menu_selection, &shading_menu_upper_left);
  3665.  
  3666. }    /* draw_shading_popup() */
  3667.  
  3668.  
  3669.  
  3670. /*****************************************************************************\
  3671. * procedure draw_view_popup                                                   *
  3672. *                                                                             *
  3673. * Purpose: This procedure draws the view popup menu in the options            *
  3674. *          dialog box.                                                        *
  3675. *                                                                             *
  3676. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3677. *             the_window: ignored.                                            *
  3678. *                                                                             *
  3679. * Created by: Greg Ferrar                                                     *
  3680. * Created on: August 21, 1992                                                 *
  3681. * Modified:                                                                   *
  3682. \*****************************************************************************/
  3683.  
  3684. pascal void draw_view_popup (WindowPtr the_window, short item_number)
  3685. {
  3686.  
  3687.     /* Draw the popup */
  3688.     draw_any_popup (options_dialog, item_number, view_menu, view_menu_selection,
  3689.                     &view_menu_upper_left);
  3690.  
  3691. }    /* draw_view_popup() */
  3692.  
  3693.  
  3694.  
  3695. /*****************************************************************************\
  3696. * procedure draw_stereo_separation_popup                                      *
  3697. *                                                                             *
  3698. * Purpose: This procedure draws the stereo separation popup menu in the       *
  3699. *          options dialog box.                                                *
  3700. *                                                                             *
  3701. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3702. *             the_window: ignored.                                            *
  3703. *                                                                             *
  3704. * Created by: Greg Ferrar                                                     *
  3705. * Created on: August 21, 1992                                                 *
  3706. * Modified:                                                                   *
  3707. \*****************************************************************************/
  3708.  
  3709. pascal void draw_stereo_separation_popup (WindowPtr the_window, short item_number)
  3710. {
  3711.  
  3712.     /* Draw the popup */
  3713.     draw_any_popup (options_dialog, item_number, stereo_separation_menu,
  3714.                     stereo_separation_menu_selection,
  3715.                     &stereo_separation_menu_upper_left);
  3716.  
  3717. }    /* draw_stereo_separation_popup() */
  3718.  
  3719.  
  3720.  
  3721. /*****************************************************************************\
  3722. * procedure draw_sampling_level_popup                                         *
  3723. *                                                                             *
  3724. * Purpose: This procedure draws the sampling level popup menu in the          *
  3725. *          options dialog box.                                                *
  3726. *                                                                             *
  3727. * Parameters: item_number: the ID of the user item used as a popup menu       *
  3728. *             the_window: ignored.                                            *
  3729. *                                                                             *
  3730. * Created by: Greg Ferrar                                                     *
  3731. * Created on: August 21, 1992                                                 *
  3732. * Modified:                                                                   *
  3733. \*****************************************************************************/
  3734.  
  3735. pascal void draw_sampling_level_popup (WindowPtr the_window, short item_number)
  3736. {
  3737.  
  3738.     /* Draw the popup */
  3739.     draw_any_popup (options_dialog, item_number, sampling_level_menu,
  3740.                     sampling_level_menu_selection,
  3741.                     &sampling_level_menu_upper_left);
  3742.  
  3743. }    /* draw_sampling_level_popup() */
  3744.  
  3745.  
  3746.  
  3747. /*****************************************************************************\
  3748. * procedure show_about_dialog                                                 *
  3749. *                                                                             *
  3750. * Purpose: This procedure displays the About... dialog.                       *
  3751. *                                                                             *                                                                             *
  3752. * Created by: Greg Ferrar                                                     *
  3753. * Created on: August 22, 1992                                                 *
  3754. * Modified:                                                                   *
  3755. \*****************************************************************************/
  3756. void show_about_dialog()
  3757. {
  3758.  
  3759.     short    item;
  3760.     Boolean    credits_showing = FALSE;
  3761.     GrafPtr    temp_port;
  3762.  
  3763.     /* Show the About... dialog */    
  3764.     ShowWindow(about_dialog);
  3765.     SelectWindow(about_dialog);
  3766.     GetPort(&temp_port);
  3767.     SetPort(about_dialog);
  3768.         
  3769.     /* Wait for user to click Okay! */
  3770.     do 
  3771.         {
  3772.     
  3773.         /* Wait for a click in a button */    
  3774.         ModalDialog (0, &item);
  3775.  
  3776.         /* If user clicked on the picture, and QuickTime is available, run RTrace movie */
  3777.         if ((item == ABOUT_TEXT_PICT_USERITEM) && (quicktime_available))
  3778.             run_rtrace_movie();
  3779.  
  3780.         /* Check for click in the More or Back button */
  3781.         if (item == MORE_BUTTON)
  3782.             {
  3783.             
  3784.             /* Is it More or Back? */
  3785.             if (credits_showing)
  3786.         
  3787.                 /* It's Back */        
  3788.                 {
  3789.  
  3790.                 /* Hide the credits and show the About pictures */
  3791.                 HideDItem(about_dialog, ABOUT_CREDITS_PICT_USERITEM);
  3792.                 ShowDItem(about_dialog, ABOUT_PICT_USERITEM);
  3793.                 ShowDItem(about_dialog, ABOUT_TEXT_PICT_USERITEM);
  3794.                 
  3795.                 /* Change the button from Back to More */
  3796.                 SetCTitle(about_more_button_handle, "\pMore");
  3797.                 
  3798.                 /* Remember that the credits aren't showing anymore */
  3799.                 credits_showing = FALSE;
  3800.                 
  3801.                 }
  3802.             
  3803.             else    /* It's More */
  3804.                 {
  3805.  
  3806.                 /* Hide the About pictures and show the credits */
  3807.                 HideDItem(about_dialog, ABOUT_PICT_USERITEM);
  3808.                 HideDItem(about_dialog, ABOUT_TEXT_PICT_USERITEM);
  3809.                 ShowDItem(about_dialog, ABOUT_CREDITS_PICT_USERITEM);
  3810.                 
  3811.                 /* Change the button from More to Back */
  3812.                 SetCTitle(about_more_button_handle, "\pBack");
  3813.                 
  3814.                 /* Remember that the credits are showing */
  3815.                 credits_showing = TRUE;
  3816.                 
  3817.                 }
  3818.             }
  3819.         }
  3820.     while (item != OKAY_BUTTON);
  3821.     
  3822.     /* If they exited from the Credits view, change things back */
  3823.     if (credits_showing)
  3824.         {
  3825.         HideDItem(about_dialog, ABOUT_CREDITS_PICT_USERITEM);
  3826.         ShowDItem(about_dialog, ABOUT_PICT_USERITEM);
  3827.         ShowDItem(about_dialog, ABOUT_TEXT_PICT_USERITEM);
  3828.         SetCTitle(about_more_button_handle, "\pMore");
  3829.         }
  3830.     
  3831.     /* Hide the dialog */
  3832.     HideWindow (about_dialog);
  3833.  
  3834.     /* Restore the GrafPort */
  3835.     SetPort(temp_port);
  3836.  
  3837.  
  3838. }    /* show_about_dialog() */
  3839.  
  3840.  
  3841.  
  3842. /*****************************************************************************\
  3843. * procedure run_rtrace_movie                                                  *
  3844. *                                                                             *
  3845. * Purpose: This runs the RTrace movie when the user clicks on the text.       *
  3846. *                                                                             *                                                                             *
  3847. * Created by: Greg Ferrar                                                     *
  3848. * Created on: August 22, 1992                                                 *
  3849. * Modified:                                                                   *
  3850. \*****************************************************************************/
  3851.  
  3852. void run_rtrace_movie(void)
  3853. {
  3854.  
  3855.     FSSpec    fsspec;
  3856.     Movie    movie;
  3857.     Rect    movie_bounds;
  3858.     long    proc_id;
  3859.     short    error;
  3860.     short    resource_refnum;
  3861.  
  3862.     /* Create the FSSpec for the movie file */
  3863.     error = GetWDInfo (temp_folder_wd_id, &(fsspec.vRefNum), &(fsspec.parID), &proc_id);
  3864.     if (error) return;
  3865.     strcpy ((char *) fsspec.name, (char *) "~~rtrace_movie");
  3866.     CtoPstr ((char *) fsspec.name);
  3867.  
  3868.     /* Open the movie file */
  3869.     error = OpenMovieFile(&fsspec, &resource_refnum, 0);
  3870.     if (error) return;
  3871.  
  3872.     error = NewMovieFromFile( &movie, resource_refnum, NULL, NULL, 0, NULL);
  3873.     if (error) return;
  3874.  
  3875.     /* Move the movie to the upper left corner of the window */
  3876.     GetMovieBox( movie, &movie_bounds);
  3877.     OffsetRect(&movie_bounds, about_rtrace_image_bounds.left - movie_bounds.left + 8,
  3878.                                 about_rtrace_image_bounds.top - movie_bounds.top - 16);
  3879.     SetMovieBox(movie, &movie_bounds);
  3880.  
  3881.     /* Set up the window for the movie to play in */
  3882.     SetMovieGWorld(movie, NULL, NULL);
  3883.  
  3884.     /* Play the movie */
  3885.     GoToBeginningOfMovie(movie);
  3886.     PrerollMovie(movie, 0, 0);
  3887.     SetMovieActive(movie, TRUE);
  3888.     StartMovie(movie);
  3889.  
  3890.     /* Keep playing until we're done */
  3891.     while (!IsMovieDone(movie))
  3892.         MoviesTask(movie, 0);
  3893.  
  3894.     /* Release memory used by movie */
  3895.     DisposeMovie(movie);
  3896.  
  3897.     /* Close the movie file */
  3898.     CloseMovieFile(resource_refnum);
  3899.  
  3900.     /* Redraw the PICT version of the image */
  3901.     draw_about_text_picture (about_dialog, 0);
  3902.  
  3903. }    /* run_rtrace_movie() */
  3904.  
  3905.  
  3906.  
  3907. /*****************************************************************************\
  3908. * procedure show_preferences_dialog                                           *
  3909. *                                                                             *
  3910. * Purpose: This procedure displays the preferences dialog, and sets the       *
  3911. *          dialog items according to the preferences.                         *
  3912. *          change the preferences.                                            *
  3913. *                                                                             *                                                                             *
  3914. * Created by: Greg Ferrar                                                     *
  3915. * Created on: September 25, 1992                                              *
  3916. * Modified:                                                                   *
  3917. \*****************************************************************************/
  3918. void show_preferences_dialog(void)
  3919. {
  3920.  
  3921.     short    type;
  3922.     Handle    handle;
  3923.     Rect    box;
  3924.     Str255    string;
  3925.  
  3926.     /* set the checkboxes according the preferences */
  3927.     SetCtlValue (show_image_rendering_checkbox, show_image_rendering);
  3928.     SetCtlValue (allow_background_tasks_checkbox, allow_background_tasks);
  3929.     SetCtlValue (keep_image_in_memory_checkbox, keep_image_in_memory);
  3930.     SetCtlValue (show_status_window_checkbox, show_status_window_flag);
  3931.     SetCtlValue (hide_options_window_checkbox, hide_options_window_flag);
  3932.     SetCtlValue (show_about_window_checkbox, show_about_window_flag);
  3933.     
  3934.     /* Set the relinquish control text according to the preferences */
  3935.     NumToString (time_between_events, string);
  3936.     GetDItem (preferences_dialog, ALLOW_BACKGROUND_TASKS_NUM, &type, &handle, &box);
  3937.     SetIText (handle, string);
  3938.     
  3939.     /* If events are disabled, select the dummy edittext item */
  3940.     if (!allow_background_tasks)
  3941.         SelIText (preferences_dialog, DUMMY_EDITTEXT, 0, 32767);
  3942.  
  3943.     /* Bring the preferences window to the front */
  3944.     ShowWindow (preferences_dialog);
  3945.     SelectWindow (preferences_dialog);
  3946.  
  3947. }    /* show_preferences_dialog() */
  3948.  
  3949.  
  3950.  
  3951. /*****************************************************************************\
  3952. * procedure handle_preferences_selection                                      *
  3953. *                                                                             *
  3954. * Purpose: This procedure handles a click in an item in the preferences       *
  3955. *          dialog.                                                            *
  3956. *                                                                             *                                                                             *
  3957. * Created by: Greg Ferrar                                                     *
  3958. * Created on: September 25, 1992                                              *
  3959. * Modified:                                                                   *
  3960. \*****************************************************************************/
  3961. void handle_preferences_selection(short item_hit)
  3962. {
  3963.  
  3964.     Boolean    new_show_image_rendering;
  3965.     Boolean    new_keep_image_in_memory;
  3966.     short    type;
  3967.     Handle    handle;
  3968.     Rect    box;
  3969.     Str255    string;        /* temporary string */
  3970.  
  3971.     switch (item_hit)
  3972.         {
  3973.         
  3974.             case ALLOW_BACKGROUND_TASKS_CHECKBOX:
  3975.             handle_checkbox_click (allow_background_tasks_checkbox);
  3976.             break;            
  3977.         
  3978.             case SHOW_IMAGE_RENDERING_CHECKBOX:
  3979.             handle_checkbox_click (show_image_rendering_checkbox);
  3980.             break;            
  3981.         
  3982.             case KEEP_IMAGE_IN_MEMORY_CHECKBOX:
  3983.             handle_checkbox_click (keep_image_in_memory_checkbox);
  3984.             break;            
  3985.         
  3986.             case SHOW_STATUS_WINDOW_CHECKBOX:
  3987.             handle_checkbox_click (show_status_window_checkbox);
  3988.             break;            
  3989.         
  3990.             case HIDE_OPTIONS_WINDOW_CHECKBOX:
  3991.             handle_checkbox_click (hide_options_window_checkbox);
  3992.             break;            
  3993.         
  3994.             case SHOW_ABOUT_WINDOW_CHECKBOX:
  3995.             handle_checkbox_click (show_about_window_checkbox);
  3996.             break;            
  3997.         
  3998.             case OKAY_BUTTON:
  3999.             /* Don't let user close window until the ticks between events number is
  4000.                 valid */
  4001.             if (GetCtlValue(allow_background_tasks_checkbox)
  4002.                 && !is_valid_param_int(preferences_dialog, ALLOW_BACKGROUND_TASKS_NUM,
  4003.                                         ALLOW_BACKGROUND_TASKS_LABEL, 1, INT_MAX))
  4004.                 {
  4005.                 
  4006.                 /* Redraw the dialog in case it was obscured by the error dialog */
  4007.                 DrawDialog(preferences_dialog);
  4008.                 
  4009.                 /* We're not done yet */
  4010.                 item_hit = 0;
  4011.                 
  4012.                 }
  4013.             
  4014.             else    /* Close the preferences dialog, and accept the new choices */
  4015.                 {
  4016.                 
  4017.                 /* Hide the preferences dialog */
  4018.                 HideWindow (preferences_dialog);
  4019.             
  4020.                 /* get the new preferences selections from the check boxes */
  4021.                 new_show_image_rendering = GetCtlValue (show_image_rendering_checkbox);
  4022.                 allow_background_tasks = GetCtlValue (allow_background_tasks_checkbox);
  4023.                 new_keep_image_in_memory = GetCtlValue (keep_image_in_memory_checkbox);
  4024.                 show_status_window_flag = GetCtlValue (show_status_window_checkbox);
  4025.                 hide_options_window_flag = GetCtlValue (hide_options_window_checkbox);
  4026.                 show_about_window_flag = GetCtlValue (show_about_window_checkbox);
  4027.             
  4028.                 /* If there was an offscreen image, but there isn't anymore, get rid of
  4029.                     the one that's there. */
  4030.                 if ((keep_image_in_memory) && (!new_keep_image_in_memory) && (is_offscreen_port))
  4031.                     dispose_offscreen_port();
  4032.             
  4033.                 /* If there should no longer be an image window, hide it. */
  4034.                 if ((show_image_rendering) && (!new_show_image_rendering))
  4035.                     hide_image_window();
  4036.                 if ((!show_image_rendering) && (new_show_image_rendering))
  4037.                     show_image_window(FALSE);
  4038.             
  4039.                 /* If there are background tasks now, get the number of ticks between. */
  4040.                 GetDItem (preferences_dialog, ALLOW_BACKGROUND_TASKS_NUM, &type, &handle, &box);
  4041.                 GetIText (handle, string);
  4042.                 StringToNum (string, &time_between_events);
  4043.             
  4044.                 /* If we are rendering, reinstall the VBL task at this new frequency */
  4045.                 if (rendering)
  4046.                     {
  4047.                     
  4048.                     /* If there is a VBL, get rid of it */
  4049.                     if (vbl_installed)
  4050.                         remove_get_event_vbl();
  4051.             
  4052.                     /* If there should be a VBL now, install it */
  4053.                     if (allow_background_tasks)
  4054.                         install_get_event_vbl();
  4055.                     
  4056.                     }
  4057.             
  4058.                 /* Save the new preferences */
  4059.                 show_image_rendering = new_show_image_rendering;
  4060.                 keep_image_in_memory = new_keep_image_in_memory;
  4061.                 
  4062.                 /* Write the preferences to the preferences file */
  4063.                 write_preferences();
  4064.                 
  4065.                 /* If we're faking a button click, dehilight it */
  4066.                 HiliteControl(preferences_okay_button_handle, 0);
  4067.  
  4068.                 }
  4069.             
  4070.         default:;    /* all other items take care of themselves */
  4071.         }
  4072.     
  4073. }    /* handle_preferences_selection() */
  4074.  
  4075.  
  4076.  
  4077. /*****************************************************************************\
  4078. * procedure save_image_filter                                                 *
  4079. *                                                                             *
  4080. * Purpose: This procedure filters events in the save... dialog.               *
  4081. *                                                                             *                                                                             *
  4082. * Parameters: the_dialog: the save... dialog.                                 *
  4083. *             the_event:  the event which occurred                            *
  4084. *             the_item:   the item which was hit, if any                      *
  4085. *                                                                             *                                                                             *
  4086. * Created by: Greg Ferrar                                                     *
  4087. * Created on: August 22, 1992                                                 *
  4088. * Modified:                                                                   *
  4089. *   Reid Judd  Oct 18,'92   Check for <Enter> key='\3' on extended keyboard   *
  4090. \*****************************************************************************/
  4091.  
  4092. pascal Boolean
  4093. save_image_filter (DialogPtr the_dialog, EventRecord *the_event, int *the_item)
  4094. {
  4095.  
  4096.     GrafPtr        temp_port;
  4097.     Rect        box;
  4098.     Handle        item;
  4099.     short        type;
  4100.     char         *filename;
  4101.     MenuHandle    menu;
  4102.     short        useritem_id;
  4103.     Point        *upper_left;
  4104.     short        *selection;
  4105.     short        menu_id;
  4106.     
  4107.     /* Decide which menu to use, depending on whether there is animation */
  4108.     if (GetCtlValue(animate_checkbox))
  4109.         {
  4110.         
  4111.         /* Use animation menu */
  4112.         menu = save_anim_file_type_menu;
  4113.         useritem_id = SAVE_FILE_TYPE_POPUP;
  4114.         upper_left = &save_anim_file_type_menu_upper_left;
  4115.         selection = &save_anim_file_type_menu_selection;
  4116.         menu_id = SAVE_ANIM_FILE_TYPE_MENU;
  4117.         
  4118.         }
  4119.         
  4120.     else
  4121.         {
  4122.         
  4123.         /* Use image menu */
  4124.         menu = save_file_type_menu;
  4125.         useritem_id = SAVE_FILE_TYPE_POPUP;
  4126.         upper_left = &save_file_type_menu_upper_left;
  4127.         selection = &save_file_type_menu_selection;
  4128.         menu_id = SAVE_FILE_TYPE_MENU;
  4129.         
  4130.         }
  4131.         
  4132.     /* Save the grafport */
  4133.     GetPort (&temp_port);
  4134.  
  4135.     /* Set the grafport to the dialog */
  4136.     SetPort (the_dialog);
  4137.  
  4138.     /* Handle the standard event: Return hit = item 1 hit */
  4139.     if ( (the_event->what == keyDown) && 
  4140.              ( ((the_event->message & charCodeMask) == '\r') ||
  4141.                ((the_event->message & charCodeMask) == '\3') ) )            
  4142.         {
  4143.         *the_item = 1;
  4144.         return TRUE;
  4145.         }
  4146.  
  4147.     /* Handle an update event for the popup menu */
  4148.     if (the_event->what == updateEvt)
  4149.         draw_any_popup (the_dialog, useritem_id, menu, *selection, upper_left);
  4150.  
  4151.     /* Handle a click in the popup menu */
  4152.     if (the_event->what == mouseDown)
  4153.         {
  4154.         
  4155.         /* Get the popup menu rectangle in global coordinates */
  4156.         GetDItem (the_dialog, useritem_id, &type, &item, &box);
  4157.         LocalToGlobal ((Point *) &box);
  4158.         LocalToGlobal ((Point *) &(box.bottom));
  4159.         
  4160.         if (PtInRect (the_event->where, &box))
  4161.             {
  4162.             
  4163.             /* Popup the menu, get a selection, and save it */
  4164.             handle_popup_click(the_dialog, menu, menu_id,
  4165.                                 SAVE_FILE_TYPE_TEXT, useritem_id, *upper_left, selection);
  4166.             
  4167.             /* Update the filename */
  4168.             filename = get_save_filename ();
  4169.             GetDItem (the_dialog, SAVE_FILENAME, &type, &item, &box);
  4170.             SetIText (item, CtoPstr(filename));
  4171.             SelIText (the_dialog, SAVE_FILENAME, 0, 32767);
  4172.  
  4173.             /* Update the popup menu in the dialog */
  4174.             InvalRect (&box);
  4175.             }
  4176.         }
  4177.  
  4178.     SetPort (temp_port);
  4179.  
  4180.     return FALSE;
  4181.  
  4182. }    /* save_image_filter() */
  4183.  
  4184.  
  4185.  
  4186. /*****************************************************************************\
  4187. * procedure get_save_filename                                                 *
  4188. *                                                                             *
  4189. * Purpose: This procedure generates an appropriate filename to save the image *
  4190. *          as, given the filename of the .sff image, and the save type.       *
  4191. *                                                                             *                                                                             *
  4192. * Parameters: returns filename to save as                                     *
  4193. *                                                                             *                                                                             *
  4194. * Created by: Greg Ferrar                                                     *
  4195. * Created on: August 27, 1992                                                 *
  4196. * Modified:                                                                   *
  4197. *   WHO          WHEN             WHAT                                        *
  4198. \*****************************************************************************/
  4199.  
  4200. char *get_save_filename (void)
  4201. {
  4202.  
  4203.     static char pathname[200];
  4204.     
  4205.     /* update the filename to reflect the file type */
  4206.     strcpy (pathname, sff_filename);
  4207.     
  4208.     /* Chop off the .sff ending */
  4209.     pathname[strlen(pathname) - 4] = 0;
  4210.     
  4211.     /* If we're animating, the menu selections mean different things that
  4212.         when we're saving an image file */
  4213.     if (GetCtlValue(animate_checkbox))
  4214.         {
  4215.  
  4216.         /* If it's a series of PICTs, add .pict */
  4217.         if (save_anim_file_type_menu_selection == 1)
  4218.             strcat (pathname, ".pict");
  4219.         else
  4220.             strcat (pathname, ".qt");        /* Quicktime movie */
  4221.  
  4222.         }
  4223.     
  4224.     else
  4225.         {
  4226.     
  4227.         /* If it's a ppm file, add .pmm */
  4228.         if (save_file_type_menu_selection == 2)
  4229.             strcat (pathname, ".ppm");
  4230.         else
  4231.             strcat (pathname, ".PICT");        /* PICT file */
  4232.     
  4233.         }
  4234.     
  4235.     /* return the filename */
  4236.     return pathname;
  4237.     
  4238. }    /* get_save_filename() */